Commit 1fae010f authored by Iustin Pop's avatar Iustin Pop
Browse files

Switch the instance_shutdown rpc to (status, data)

This patch changes the return type from this RPC call to include status
information and renames the backend method to match the RPC call name.

The patch is a little bigger than the reboot one, since this call is
used in more than one place. However, all the points of call have the
same usage pattern, so the patch is trivial.

Reviewed-by: ultrotter
parent 489fcbe9
......@@ -392,7 +392,7 @@ class NodeHttpServer(http.server.HttpServer):
"""
instance = objects.Instance.FromDict(params[0])
return backend.ShutdownInstance(instance)
return backend.InstanceShutdown(instance)
@staticmethod
def perspective_instance_start(params):
......
......@@ -886,7 +886,7 @@ def StartInstance(instance, extra_args):
return (True, "Instance started successfully")
def ShutdownInstance(instance):
def InstanceShutdown(instance):
"""Shut an instance down.
@note: this functions uses polling with a hardcoded timeout.
......@@ -901,14 +901,15 @@ def ShutdownInstance(instance):
running_instances = GetInstanceList([hv_name])
if instance.name not in running_instances:
return True
return (True, "Instance already stopped")
hyper = hypervisor.GetHypervisor(hv_name)
try:
hyper.StopInstance(instance)
except errors.HypervisorError, err:
logging.error("Failed to stop instance: %s" % err)
return False
msg = "Failed to stop instance %s: %s" % (instance.name, err)
logging.error(msg)
return (False, msg)
# test every 10secs for 2min
......@@ -925,18 +926,20 @@ def ShutdownInstance(instance):
try:
hyper.StopInstance(instance, force=True)
except errors.HypervisorError, err:
logging.exception("Failed to stop instance: %s" % err)
return False
msg = "Failed to force stop instance %s: %s" % (instance.name, err)
logging.error(msg)
return (False, msg)
time.sleep(1)
if instance.name in GetInstanceList([hv_name]):
logging.error("Could not shutdown instance '%s' even by destroy",
instance.name)
return False
msg = ("Could not shutdown instance %s even by destroy" %
instance.name)
logging.error(msg)
return (False, msg)
_RemoveBlockDevLinks(instance.name, instance.disks)
return True
return (True, "Instance has been shutdown successfully")
def InstanceReboot(instance, reboot_type, extra_args):
......@@ -975,7 +978,7 @@ def InstanceReboot(instance, reboot_type, extra_args):
return (False, msg)
elif reboot_type == constants.INSTANCE_REBOOT_HARD:
try:
ShutdownInstance(instance)
InstanceShutdown(instance)
StartInstance(instance, extra_args)
except errors.HypervisorError, err:
msg = "Failed to hard reboot instance %s: %s" % (instance.name, err)
......
......@@ -2796,8 +2796,11 @@ class LURebootInstance(LogicalUnit):
if msg:
raise errors.OpExecError("Could not reboot instance: %s" % msg)
else:
if not self.rpc.call_instance_shutdown(node_current, instance):
raise errors.OpExecError("could not shutdown instance for full reboot")
result = self.rpc.call_instance_shutdown(node_current, instance)
msg = result.RemoteFailMsg()
if msg:
raise errors.OpExecError("Could not shutdown instance for"
" full reboot: %s" % msg)
_ShutdownInstanceDisks(self, instance)
_StartInstanceDisks(self, instance, ignore_secondaries)
result = self.rpc.call_instance_start(node_current, instance, extra_args)
......@@ -2851,8 +2854,9 @@ class LUShutdownInstance(LogicalUnit):
node_current = instance.primary_node
self.cfg.MarkInstanceDown(instance.name)
result = self.rpc.call_instance_shutdown(node_current, instance)
if result.failed or not result.data:
self.proc.LogWarning("Could not shutdown instance")
msg = result.RemoteFailMsg()
if msg:
self.proc.LogWarning("Could not shutdown instance: %s" % msg)
_ShutdownInstanceDisks(self, instance)
......@@ -3102,12 +3106,14 @@ class LURemoveInstance(LogicalUnit):
instance.name, instance.primary_node)
result = self.rpc.call_instance_shutdown(instance.primary_node, instance)
if result.failed or not result.data:
msg = result.RemoteFailMsg()
if msg:
if self.op.ignore_failures:
feedback_fn("Warning: can't shutdown instance")
feedback_fn("Warning: can't shutdown instance: %s" % msg)
else:
raise errors.OpExecError("Could not shutdown instance %s on node %s" %
(instance.name, instance.primary_node))
raise errors.OpExecError("Could not shutdown instance %s on"
" node %s: %s" %
(instance.name, instance.primary_node, msg))
logging.info("Removing block devices for instance %s", instance.name)
......@@ -3454,15 +3460,17 @@ class LUFailoverInstance(LogicalUnit):
instance.name, source_node)
result = self.rpc.call_instance_shutdown(source_node, instance)
if result.failed or not result.data:
msg = result.RemoteFailMsg()
if msg:
if self.op.ignore_consistency:
self.proc.LogWarning("Could not shutdown instance %s on node %s."
" Proceeding"
" anyway. Please make sure node %s is down",
instance.name, source_node, source_node)
" Proceeding anyway. Please make sure node"
" %s is down. Error details: %s",
instance.name, source_node, source_node, msg)
else:
raise errors.OpExecError("Could not shutdown instance %s on node %s" %
(instance.name, source_node))
raise errors.OpExecError("Could not shutdown instance %s on"
" node %s: %s" %
(instance.name, source_node, msg))
feedback_fn("* deactivating the instance's disks on source node")
if not _ShutdownInstanceDisks(self, instance, ignore_primary=True):
......@@ -6083,10 +6091,11 @@ class LUExportInstance(LogicalUnit):
if self.op.shutdown:
# shutdown the instance, but not the disks
result = self.rpc.call_instance_shutdown(src_node, instance)
result.Raise()
if not result.data:
raise errors.OpExecError("Could not shutdown instance %s on node %s" %
(instance.name, src_node))
msg = result.RemoteFailMsg()
if msg:
raise errors.OpExecError("Could not shutdown instance %s on"
" node %s: %s" %
(instance.name, src_node, msg))
vgname = self.cfg.GetVGName()
......
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