Allow instance disks to be added with --no-wait-for-sync
authorHrvoje Ribicic <riba@google.com>
Mon, 11 Aug 2014 13:58:22 +0000 (15:58 +0200)
committerHrvoje Ribicic <riba@google.com>
Tue, 12 Aug 2014 12:12:57 +0000 (14:12 +0200)
The patch 3c260845147c6dad35e37c03ba9a7556814f3f3f fixed a bug where
adding a new disk to an instance with deactivated disks activated the
disk. However, it also introduced some erroneous behaviour, preventing
disks from being added to online instances with --no-wait-for-sync.

In line with the original meaning of the patch, this patch modifies the
check to disallow adding disks to shutdown instances with
--no-wait-for-sync, and allow doing so for online instances.

Signed-off-by: Hrvoje Ribicic <riba@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

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

index 480198d..3e5a2cd 100644 (file)
@@ -2819,11 +2819,11 @@ class LUInstanceSetParams(LogicalUnit):
                                       constants.DT_EXT),
                                      errors.ECODE_INVAL)
 
-    if not self.op.wait_for_sync and self.instance.disks_active:
+    if not self.op.wait_for_sync and not self.instance.disks_active:
       for mod in self.diskmod:
         if mod[0] == constants.DDM_ADD:
           raise errors.OpPrereqError("Can't add a disk to an instance with"
-                                     " activated disks and"
+                                     " deactivated disks and"
                                      " --no-wait-for-sync given.",
                                      errors.ECODE_INVAL)
 
index 245f023..2ecb816 100644 (file)
@@ -2159,9 +2159,8 @@ class TestLUInstanceSetParams(CmdlibTestCase):
                                    constants.IDISK_SIZE: 1024
                                  }]],
                          wait_for_sync=False)
-    self.ExecOpCodeExpectOpPrereqError(
-      op, "Can't add a disk to an instance with activated disks"
-          " and --no-wait-for-sync given.")
+    self.ExecOpCode(op)
+    self.assertFalse(self.rpc.call_blockdev_shutdown.called)
 
   def testAddDiskDownInstance(self):
     op = self.CopyOpCode(self.op,
@@ -2173,6 +2172,17 @@ class TestLUInstanceSetParams(CmdlibTestCase):
 
     self.assertTrue(self.rpc.call_blockdev_shutdown.called)
 
+  def testAddDiskDownInstanceNoWaitForSync(self):
+    op = self.CopyOpCode(self.op,
+                         disks=[[constants.DDM_ADD, -1,
+                                 {
+                                   constants.IDISK_SIZE: 1024
+                                 }]],
+                         wait_for_sync=False)
+    self.ExecOpCodeExpectOpPrereqError(
+      op, "Can't add a disk to an instance with deactivated disks"
+          " and --no-wait-for-sync given.")
+
   def testAddDiskRunningInstance(self):
     op = self.CopyOpCode(self.running_op,
                          disks=[[constants.DDM_ADD, -1,