Test disk attachment with different primary nodes
authorLisa Velden <velden@google.com>
Mon, 11 Jan 2016 11:12:49 +0000 (12:12 +0100)
committerLisa Velden <velden@google.com>
Mon, 11 Jan 2016 11:40:15 +0000 (12:40 +0100)
Test a detach/attach sequence with a DRBD disk and a different primary
node for the disk and the instance. This should raise an exception.

Signed-off-by: Lisa Velden <velden@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

test/py/cmdlib/instance_unittest.py

index 3c328dd..1a4a45b 100644 (file)
@@ -2968,6 +2968,44 @@ class TestLUInstanceSetParams(CmdlibTestCase):
     self.ExecOpCode(op)
     self.assertEqual([disk], self.cfg.GetInstanceDisks(inst.uuid))
 
+  def testDetachAttachDrbdDiskWithWrongPrimaryNode(self):
+    """Check if disk attachment with a wrong primary node fails.
+
+    """
+    disk1 = self.cfg.CreateDisk(uuid=self.mocked_disk_uuid,
+                               primary_node=self.master.uuid,
+                               secondary_node=self.snode.uuid,
+                               dev_type=constants.DT_DRBD8)
+
+    inst1 = self.cfg.AddNewInstance(disks=[disk1], primary_node=self.master,
+                                    secondary_node=self.snode)
+
+    op = self.CopyOpCode(self.op,
+                         instance_name=inst1.name,
+                         disks=[[constants.DDM_DETACH,
+                         self.mocked_disk_uuid, {}]])
+
+    self.ExecOpCode(op)
+    self.assertEqual([], self.cfg.GetInstanceDisks(inst1.uuid))
+
+    disk2 = self.cfg.CreateDisk(uuid="mock_uuid_1135",
+                               primary_node=self.snode.uuid,
+                               secondary_node=self.master.uuid,
+                               dev_type=constants.DT_DRBD8)
+
+    inst2 = self.cfg.AddNewInstance(disks=[disk2], primary_node=self.snode,
+                                    secondary_node=self.master)
+
+    op = self.CopyOpCode(self.op,
+                         instance_name=inst2.name,
+                         disks=[[constants.DDM_ATTACH, 0,
+                                 {
+                                   'uuid': self.mocked_disk_uuid
+                                 }]])
+
+    self.assertRaises(errors.OpExecError, self.ExecOpCode, op)
+
+
   def testDetachAttachExtDisk(self):
     """Check attach/detach functionality of ExtStorage disks.