From fcd62d848496fb1059ad555238bea1d21214fcb4 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 14 Oct 2008 06:38:44 +0000 Subject: [PATCH] Implement parameter removal in SplitKeyVal This patch adds paramter removal in SplitKeyVal, by prefixing a value-less key with "-"; this is needed in resetting parameters back to cluster defaults, but care must be applied now that None can come from the parser. Reviewed-by: imsnah --- lib/cli.py | 3 +++ test/ganeti.cli_unittest.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/cli.py b/lib/cli.py index c10dd78d5..e3abe3a56 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -241,6 +241,7 @@ def _SplitKeyVal(opt, data): """ NO_PREFIX = "no_" + UN_PREFIX = "-" kv_dict = {} for elem in data.split(","): if "=" in elem: @@ -248,6 +249,8 @@ def _SplitKeyVal(opt, data): else: if elem.startswith(NO_PREFIX): key, val = elem[len(NO_PREFIX):], False + elif elem.startswith(UN_PREFIX): + key, val = elem[len(UN_PREFIX):], None else: key, val = elem, True if key in kv_dict: diff --git a/test/ganeti.cli_unittest.py b/test/ganeti.cli_unittest.py index 99877279e..cb3b788ae 100755 --- a/test/ganeti.cli_unittest.py +++ b/test/ganeti.cli_unittest.py @@ -61,8 +61,8 @@ class TestParseTimespec(unittest.TestCase): class TestSplitKeyVal(unittest.TestCase): """Testing case for cli._SplitKeyVal""" - DATA = "a=b,c,no_d" - RESULT = {"a": "b", "c": True, "d": False} + DATA = "a=b,c,no_d,-e" + RESULT = {"a": "b", "c": True, "d": False, "e": None} def testSplitKeyVal(self): """Test splitting""" -- GitLab