TLReplaceDisks: Add check if disks are activated
authorRené Nussbaumer <rn@google.com>
Tue, 15 Mar 2011 08:23:23 +0000 (09:23 +0100)
committerRené Nussbaumer <rn@google.com>
Tue, 15 Mar 2011 10:41:17 +0000 (11:41 +0100)
Previously we failed later with a rather useless error message. This
patch fixes this and tells the user to activate-disks if replace-disks
is in the need of activated disks rather than abort with a cryptic error
message.

Signed-off-by: René Nussbaumer <rn@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/cmdlib.py
qa/qa_instance.py

index 2da4fbc..c628a6e 100644 (file)
@@ -8358,6 +8358,30 @@ class TLReplaceDisks(Tasklet):
     return _FindFaultyInstanceDisks(self.cfg, self.rpc, self.instance,
                                     node_name, True)
 
+  def _CheckDisksActivated(self, instance):
+    """Checks if the instance disks are activated.
+
+    @param instance: The instance to check disks
+    @return: True if they are activated, False otherwise
+
+    """
+    nodes = instance.all_nodes
+
+    for idx, dev in enumerate(instance.disks):
+      for node in nodes:
+        self.lu.LogInfo("Checking disk/%d on %s", idx, node)
+        self.cfg.SetDiskID(dev, node)
+
+        result = self.rpc.call_blockdev_find(node, dev)
+
+        if result.offline:
+          continue
+        elif result.fail_msg or not result.payload:
+          return False
+
+    return True
+
+
   def CheckPrereq(self):
     """Check prerequisites.
 
@@ -8421,6 +8445,10 @@ class TLReplaceDisks(Tasklet):
                                  errors.ECODE_INVAL)
 
     if self.mode == constants.REPLACE_DISK_AUTO:
+      if not self._CheckDisksActivated(instance):
+        raise errors.OpPrereqError("Please run activate-disks on instance %s"
+                                   " first" % self.instance_name,
+                                   errors.ECODE_STATE)
       faulty_primary = self._FindFaultyDisks(instance.primary_node)
       faulty_secondary = self._FindFaultyDisks(secondary_node)
 
index 2728529..d13ff79 100644 (file)
@@ -263,6 +263,13 @@ def TestReplaceDisks(instance, pnode, snode, othernode):
     ]:
     AssertCommand(buildcmd(data))
 
+  AssertCommand(buildcmd(["-a"]))
+  AssertCommand(["gnt-instance", "stop", instance["name"]])
+  AssertCommand(buildcmd(["-a"]), fail=True)
+  AssertCommand(["gnt-instance", "activate-disks", instance["name"]])
+  AssertCommand(buildcmd(["-a"]))
+  AssertCommand(["gnt-instance", "start", instance["name"]])
+
 
 def TestInstanceExport(instance, node):
   """gnt-backup export -n ..."""