Fix bug in “gnt-node list-storage”
authorMichael Hanselmann <hansmi@google.com>
Tue, 25 Jan 2011 18:28:59 +0000 (19:28 +0100)
committerMichael Hanselmann <hansmi@google.com>
Wed, 26 Jan 2011 10:06:15 +0000 (11:06 +0100)
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 <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/storage.py
qa/qa_node.py

index 5d30396..039edac 100644 (file)
@@ -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):
index 15550f9..0b8a8af 100644 (file)
@@ -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]