From: Michael Hanselmann Date: Tue, 25 Jan 2011 18:28:59 +0000 (+0100) Subject: Fix bug in “gnt-node list-storage” X-Git-Tag: v2.4.0~1^2~11 X-Git-Url: https://code.grnet.gr/git/ganeti-local/commitdiff_plain/5ae7cd1183c7e47572bc9e7b286f2ac71b1a0104 Fix bug in “gnt-node list-storage” LVM PV storage units would always show as allocatable, even when they weren't. For some reason I have not been able to determine, the function parsing the attributes (“_GetAllocatable”) was not even called and the list opcode simply returned the attribute string as the value (e.g. “a-”). Removing “@staticmethod” did the trick and then I just moved it to module level. A QA test is included. Signed-off-by: Michael Hanselmann Reviewed-by: Iustin Pop --- diff --git a/lib/storage.py b/lib/storage.py index 5d30396..039edac 100644 --- a/lib/storage.py +++ b/lib/storage.py @@ -332,18 +332,23 @@ class _LvmBase(_Base): # pylint: disable-msg=W0223 yield fields +def _LvmPvGetAllocatable(attr): + """Determines whether LVM PV is allocatable. + + @rtype: bool + + """ + if attr: + return (attr[0] == "a") + else: + logging.warning("Invalid PV attribute: %r", attr) + return False + + class LvmPvStorage(_LvmBase): # pylint: disable-msg=W0223 """LVM Physical Volume storage unit. """ - @staticmethod - def _GetAllocatable(attr): - if attr: - return (attr[0] == "a") - else: - logging.warning("Invalid PV attribute: %r", attr) - return False - LIST_COMMAND = "pvs" # Make sure to update constants.VALID_STORAGE_FIELDS when changing field @@ -353,7 +358,7 @@ class LvmPvStorage(_LvmBase): # pylint: disable-msg=W0223 (constants.SF_SIZE, ["pv_size"], _ParseSize), (constants.SF_USED, ["pv_used"], _ParseSize), (constants.SF_FREE, ["pv_free"], _ParseSize), - (constants.SF_ALLOCATABLE, ["pv_attr"], _GetAllocatable), + (constants.SF_ALLOCATABLE, ["pv_attr"], _LvmPvGetAllocatable), ] def _SetAllocatable(self, name, allocatable): diff --git a/qa/qa_node.py b/qa/qa_node.py index 15550f9..0b8a8af 100644 --- a/qa/qa_node.py +++ b/qa/qa_node.py @@ -150,11 +150,13 @@ def TestNodeStorage(): else: test_allocatable = ["yes", "no"] - if (constants.SF_ALLOCATABLE in - constants.MODIFIABLE_STORAGE_FIELDS.get(storage_type, [])): - assert_fn = AssertEqual - else: + fail = (constants.SF_ALLOCATABLE not in + constants.MODIFIABLE_STORAGE_FIELDS.get(storage_type, [])) + + if fail: assert_fn = AssertNotEqual + else: + assert_fn = AssertEqual for i in test_allocatable: cmd = ["gnt-node", "modify-storage", "--allocatable", i, @@ -162,6 +164,19 @@ def TestNodeStorage(): assert_fn(StartSSH(master["primary"], utils.ShellQuoteArgs(cmd)).wait(), 0) + # Verify list output + cmd = ["gnt-node", "list-storage", "--storage-type", storage_type, + "--output=name,allocatable", "--separator=|", + "--no-headers", node_name] + listout = qa_utils.GetCommandOutput(master["primary"], + utils.ShellQuoteArgs(cmd)) + for line in listout.splitlines(): + (vfy_name, vfy_allocatable) = line.split("|") + if vfy_name == st_name and not fail: + AssertEqual(vfy_allocatable, i[0].upper()) + else: + AssertEqual(vfy_allocatable, st_allocatable) + # Test repair functionality cmd = ["gnt-node", "repair-storage", node_name, storage_type, st_name]