diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded index f2b85e7d724f6cdb21f5309c9e5355e01bcdd756..bfba3929a18fce04dc0d96b071cb5c592726708b 100755 --- a/daemons/ganeti-noded +++ b/daemons/ganeti-noded @@ -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): diff --git a/lib/backend.py b/lib/backend.py index 48d0dc8ca794520ad77226bfc531ff338252dc90..1c9cfdbaaff833f9525319db0fb1990c288f521e 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -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) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 954fd1d82a31a2fb8afa9b576bd9e91123b134e3..a06decbc59ab0ac27b6e74a429caa956c4028ac4 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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()