rpc.py: override default storage type in node info
authorHelga Velroyen <helgav@google.com>
Fri, 21 Jun 2013 10:53:05 +0000 (12:53 +0200)
committerHelga Velroyen <helgav@google.com>
Thu, 27 Jun 2013 09:05:27 +0000 (11:05 +0200)
This patch changes the semantics of dealing with the result
of the RPC call "node_info" when converting them into a
LegacyNodeInfo. A legacy node info, can only hold storage
information about one storage type, which so far was always
LVM storage. With the recent changes in the RCP call
'node_info', a node info call returns storage info of several
storage types and not necessarily with lvm being the first
in the list. In order to be backward-compatible with tools
that assume that LVM storage is the only storage type, we
make sure, that MakeLegacyNode info can be called
requesting LVM info specifically. This is just an interim
solution to not break everything at once. The long-term
goal is to get rid of MakeLegacyNodeInfo completely.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

lib/rpc.py
test/py/ganeti.rpc_unittest.py

index f3480c2..e01e2a3 100644 (file)
@@ -634,7 +634,14 @@ def _AddDefaultStorageInfoToLegacyNodeInfo(result, space_info,
     default_space_info = space_info[0]
 
   if require_vg_info:
-    if no_defaults or not default_space_info["type"] == constants.ST_LVM_VG:
+    # if lvm storage is required, ignore the actual default and look for LVM
+    lvm_info_found = False
+    for space_entry in space_info:
+      if space_entry["type"] == constants.ST_LVM_VG:
+        default_space_info = space_entry
+        lvm_info_found = True
+        continue
+    if not lvm_info_found:
       raise errors.OpExecError("LVM volume group info required, but not"
                                " provided.")
 
index 0674b4b..d2eee4b 100755 (executable)
@@ -957,5 +957,55 @@ class TestLegacyNodeInfo(unittest.TestCase):
     self.assertEqual(result, self.STD_DICT)
 
 
+class TestAddDefaultStorageInfoToLegacyNodeInfo(unittest.TestCase):
+
+  def setUp(self):
+    self.free_storage_file = 23
+    self.total_storage_file = 42
+    self.free_storage_lvm = 69
+    self.total_storage_lvm = 666
+    self.node_info = [{"name": "mynode",
+                       "type": constants.ST_FILE,
+                       "storage_free": self.free_storage_file,
+                       "storage_size": self.total_storage_file},
+                      {"name": "mynode",
+                       "type": constants.ST_LVM_VG,
+                       "storage_free": self.free_storage_lvm,
+                       "storage_size": self.total_storage_lvm},
+                      {"name": "mynode",
+                       "type": constants.ST_LVM_PV,
+                       "storage_free": 33,
+                       "storage_size": 44}]
+
+  def testAddDefaultStorageInfoToLegacyNodeInfo(self):
+    result = {}
+    has_lvm = False
+    rpc._AddDefaultStorageInfoToLegacyNodeInfo(result, self.node_info, has_lvm)
+    self.assertEqual(self.free_storage_file, result["storage_free"])
+    self.assertEqual(self.total_storage_file, result["storage_size"])
+
+  def testAddDefaultStorageInfoToLegacyNodeInfoOverrideDefault(self):
+    result = {}
+    has_lvm = True
+    rpc._AddDefaultStorageInfoToLegacyNodeInfo(result, self.node_info, has_lvm)
+    self.assertEqual(self.free_storage_lvm, result["storage_free"])
+    self.assertEqual(self.total_storage_lvm, result["storage_size"])
+
+  def testAddDefaultStorageInfoToLegacyNodeInfoNoDefaults(self):
+    result = {}
+    has_lvm = False
+    rpc._AddDefaultStorageInfoToLegacyNodeInfo(result, self.node_info[-1:],
+                                               has_lvm)
+    self.assertFalse("storage_free" in result)
+    self.assertFalse("storage_size" in result)
+
+  def testAddDefaultStorageInfoToLegacyNodeInfoNoLvm(self):
+    result = {}
+    has_lvm = True
+    self.assertRaises(errors.OpExecError,
+                      rpc._AddDefaultStorageInfoToLegacyNodeInfo,
+                      result, self.node_info[-1:], has_lvm)
+
+
 if __name__ == "__main__":
   testutils.GanetiTestProgram()