Commit 9026e935 authored by René Nussbaumer's avatar René Nussbaumer

TLReplaceDisks: Add check if disks are activated

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: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 7738342c
......@@ -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)
......
......@@ -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 ..."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment