Move disk template unit tests to test/py/cmdlib/
authorHelga Velroyen <helgav@google.com>
Wed, 9 Oct 2013 11:34:26 +0000 (13:34 +0200)
committerHelga Velroyen <helgav@google.com>
Fri, 11 Oct 2013 11:13:41 +0000 (13:13 +0200)
This patch moves some unit tests related to dis/enabling
disk templates from ganeti.cmdlib.cluster_unittest.py
to cmdlib/cluster_unittest.py to utilized the new cmdlib
unit test framework.

Signed-off-by: Helga Velroyen <helgav@google.com>
Reviewed-by: Michele Tartara <mtartara@google.com>

test/py/cmdlib/cluster_unittest.py
test/py/ganeti.cmdlib.cluster_unittest.py

index 90d91d6..aaad834 100644 (file)
@@ -799,6 +799,17 @@ class TestLUClusterSetParams(CmdlibTestCase):
     self.assertEqual(enabled_disk_templates,
                      self.cluster.enabled_disk_templates)
 
+  def testDisablingDiskTemplatesOfInstances(self):
+    old_disk_templates = [constants.DT_DISKLESS, constants.DT_PLAIN]
+    self.cfg.SetEnabledDiskTemplates(old_disk_templates)
+    self.cfg.AddNewInstance(
+      disks=[self.cfg.CreateDisk(dev_type=constants.DT_PLAIN)])
+    new_disk_templates = [constants.DT_DISKLESS, constants.DT_DRBD8]
+    op = opcodes.OpClusterSetParams(
+           enabled_disk_templates=new_disk_templates,
+           ipolicy={constants.IPOLICY_DTS: new_disk_templates})
+    self.ExecOpCodeExpectOpPrereqError(op, "least one instance using it")
+
   def testEnabledDiskTemplatesWithoutVgName(self):
     enabled_disk_templates = [constants.DT_PLAIN]
     self.cluster.volume_group_name = None
index 12460e6..7667362 100755 (executable)
@@ -76,29 +76,5 @@ class TestCheckFileStoragePath(unittest.TestCase):
         NotImplemented, "", self.enabled_disk_templates)
 
 
-class TestGetEnabledDiskTemplates(unittest.TestCase):
-
-  def testNoNew(self):
-    op_dts = [constants.DT_DISKLESS]
-    old_dts = [constants.DT_DISKLESS]
-    (enabled_dts, new_dts, disabled_dts) =\
-        cluster.LUClusterSetParams._GetDiskTemplateSetsInner(
-            op_dts, old_dts)
-    self.assertEqual(enabled_dts, old_dts)
-    self.assertEqual(new_dts, [])
-    self.assertEqual(disabled_dts, [])
-
-  def testValid(self):
-    op_dts = [constants.DT_PLAIN, constants.DT_DRBD8]
-    old_dts = [constants.DT_DISKLESS, constants.DT_PLAIN]
-    (enabled_dts, new_dts, disabled_dts) =\
-        cluster.LUClusterSetParams._GetDiskTemplateSetsInner(
-            op_dts, old_dts)
-    self.assertEqual(enabled_dts, op_dts)
-    self.assertEqual(new_dts, [constants.DT_DRBD8])
-    self.assertEqual(disabled_dts, [constants.DT_DISKLESS])
-
-
-
 if __name__ == "__main__":
   testutils.GanetiTestProgram()