Allow plain/DRBD conversions regardless of lack of disks
authorHrvoje Ribicic <riba@google.com>
Mon, 16 Mar 2015 22:54:04 +0000 (22:54 +0000)
committerHrvoje Ribicic <riba@google.com>
Tue, 17 Mar 2015 12:25:14 +0000 (13:25 +0100)
Because of trivial issues, it was impossible to use standard mechanisms
to convert a diskless plain instance to DRBD and vice versa. This
patch fixes that with a mechanism which will work until later versions,
where instances without disks organically take on the diskless
template.

Signed-off-by: Hrvoje Ribicic <riba@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

lib/cmdlib/instance.py
test/py/cmdlib/instance_unittest.py

index 95c5b0e..a22043e 100644 (file)
@@ -3271,11 +3271,16 @@ class LUInstanceSetParams(LogicalUnit):
     """Converts an instance from drbd to plain.
 
     """
-    assert len(self.instance.secondary_nodes) == 1
     assert self.instance.disk_template == constants.DT_DRBD8
+    assert len(self.instance.secondary_nodes) == 1 or not self.instance.disks
 
     pnode_uuid = self.instance.primary_node
-    snode_uuid = self.instance.secondary_nodes[0]
+
+    # it will not be possible to calculate the snode_uuid later
+    snode_uuid = None
+    if self.instance.secondary_nodes:
+      snode_uuid = self.instance.secondary_nodes[0]
+
     feedback_fn("Converting template to plain")
 
     old_disks = AnnotateDiskParams(self.instance, self.instance.disks, self.cfg)
index fec6398..5200af4 100644 (file)
@@ -2336,6 +2336,30 @@ class TestLUInstanceSetParams(CmdlibTestCase):
                          disk_template=constants.DT_PLAIN)
     self.ExecOpCode(op)
 
+  def testConvertDisklessDRBDToPlain(self):
+    self.cfg.SetIPolicyField(
+      constants.ISPECS_MIN, constants.ISPEC_DISK_COUNT, 0)
+    self.inst.disks = []
+    self.inst.disk_template = constants.DT_DRBD8
+
+    op = self.CopyOpCode(self.op,
+                         disk_template=constants.DT_PLAIN)
+    self.ExecOpCode(op)
+
+    self.assertEqual(self.inst.disk_template, constants.DT_PLAIN)
+
+  def testConvertDisklessPlainToDRBD(self):
+    self.cfg.SetIPolicyField(
+      constants.ISPECS_MIN, constants.ISPEC_DISK_COUNT, 0)
+    self.inst.disks = []
+    self.inst.disk_template = constants.DT_PLAIN
+
+    op = self.CopyOpCode(self.op,
+                         disk_template=constants.DT_DRBD8,
+                         remote_node=self.snode.name)
+    self.ExecOpCode(op)
+
+    self.assertEqual(self.inst.disk_template, constants.DT_DRBD8)
 
 class TestLUInstanceChangeGroup(CmdlibTestCase):
   def setUp(self):