rpc: Remove duplicated logic, fix unittests
authorMichael Hanselmann <hansmi@google.com>
Wed, 12 Sep 2012 12:41:24 +0000 (14:41 +0200)
committerMichael Hanselmann <hansmi@google.com>
Wed, 12 Sep 2012 13:15:08 +0000 (15:15 +0200)
Commit 5fce6a89 changed RpcRunner._InstDict to add the disk parameters
on all encoded instances. It didn't remove a special case in
“_InstDictOspDp”. Update and fix unittests as well.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: René Nussbaumer <rn@google.com>

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

index f1a470e..b06c3c7 100644 (file)
@@ -735,9 +735,7 @@ class RpcRunner(_RpcClientBase,
     """Wrapper for L{_InstDict}.
 
     """
-    updated_inst = self._InstDict(instance, osp=osparams)
-    updated_inst["disks"] = self._DisksDictDP((instance.disks, instance))
-    return updated_inst
+    return self._InstDict(instance, osp=osparams)
 
   def _DisksDictDP(self, (disks, instance)):
     """Wrapper for L{AnnotateDiskParams}.
index 16857b5..54870f4 100755 (executable)
@@ -798,8 +798,13 @@ class TestRpcRunner(unittest.TestCase):
           constants.NIC_MODE: "mymode",
           }),
         ],
-      disk_template=constants.DT_DISKLESS,
-      disks=[])
+      disk_template=constants.DT_PLAIN,
+      disks=[
+        objects.Disk(dev_type=constants.LD_LV, size=4096,
+                     logical_id=("vg", "disk6120")),
+        objects.Disk(dev_type=constants.LD_LV, size=1024,
+                     logical_id=("vg", "disk8508")),
+        ])
     inst.UpgradeConfig()
 
     cfg = _FakeConfigForRpcRunner(cluster=cluster)
@@ -852,7 +857,7 @@ class TestRpcRunner(unittest.TestCase):
       })
 
     # Instance with hypervisor and backend parameters
-    result = runner._encoder((rpc_defs.ED_INST_DICT_HVP_BEP, (inst, {
+    result = runner._encoder((rpc_defs.ED_INST_DICT_HVP_BEP_DP, (inst, {
       constants.HT_KVM: {
         constants.HV_BOOT_ORDER: "xyz",
         },
@@ -866,6 +871,20 @@ class TestRpcRunner(unittest.TestCase):
     self.assertEqual(result["hvparams"][constants.HT_KVM], {
       constants.HV_BOOT_ORDER: "xyz",
       })
+    self.assertEqual(result["disks"], [{
+      "dev_type": constants.LD_LV,
+      "size": 4096,
+      "logical_id": ("vg", "disk6120"),
+      "params": constants.DISK_DT_DEFAULTS[inst.disk_template],
+      }, {
+      "dev_type": constants.LD_LV,
+      "size": 1024,
+      "logical_id": ("vg", "disk8508"),
+      "params": constants.DISK_DT_DEFAULTS[inst.disk_template],
+      }])
+
+    self.assertTrue(compat.all(disk.params == {} for disk in inst.disks),
+                    msg="Configuration objects were modified")
 
 
 if __name__ == "__main__":