From 20e01edd2811c9914724936624a5ff0818ce9024 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Tue, 20 Jan 2009 10:11:48 +0000 Subject: [PATCH] Convert AddOSToInstance to (status, data) This allows the install and reinstall instance to return (hopefully) relevant log files from the OS create scripts. Reviewed-by: ultrotter --- lib/backend.py | 7 +++++-- lib/cmdlib.py | 16 ++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/backend.py b/lib/backend.py index 09a5b8892..2ce138527 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -681,9 +681,12 @@ def AddOSToInstance(instance): logging.error("os create command '%s' returned error: %s, logfile: %s," " output: %s", result.cmd, result.fail_reason, logfile, result.output) - return False + lines = [val.encode("string_escape") + for val in utils.TailFile(logfile, lines=20)] + return (False, "OS create script failed (%s), last lines in the" + " log file:\n%s" % (result.fail_reason, "\n".join(lines))) - return True + return (True, "Successfully installed") def RunRenameInstance(instance, old_name): diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 6a58548a7..ce5edc602 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2837,11 +2837,11 @@ class LUReinstallInstance(LogicalUnit): try: feedback_fn("Running the instance OS create scripts...") result = self.rpc.call_instance_os_add(inst.primary_node, inst) - result.Raise() - if not result.data: + msg = result.RemoteFailMsg() + if msg: raise errors.OpExecError("Could not install OS for instance %s" - " on node %s" % - (inst.name, inst.primary_node)) + " on node %s: %s" % + (inst.name, inst.primary_node, msg)) finally: _ShutdownInstanceDisks(self, inst) @@ -4512,11 +4512,11 @@ class LUCreateInstance(LogicalUnit): if self.op.mode == constants.INSTANCE_CREATE: feedback_fn("* running the instance OS create scripts...") result = self.rpc.call_instance_os_add(pnode_name, iobj) - result.Raise() - if not result.data: + msg = result.RemoteFailMsg() + if msg: raise errors.OpExecError("Could not add os for instance %s" - " on node %s" % - (instance, pnode_name)) + " on node %s: %s" % + (instance, pnode_name, msg)) elif self.op.mode == constants.INSTANCE_IMPORT: feedback_fn("* running the instance OS import scripts...") -- GitLab