From 5188ab3773f1b4d11a82bafda3a0a91bf54f3c7e Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Wed, 1 Oct 2008 09:27:07 +0000 Subject: [PATCH] Remove last use of utils.RunCmd from the watcher MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The watcher has one last use of ganeti commands as opposed to sending requests via luxi. The patch changes this to use the cli functions. The patch also has two other changes: - fix the docstring for OpVerifyDisks (found out while converting this) - enable stderr logging on the watcher when β-dβ is passes Reviewed-by: imsnah --- daemons/ganeti-watcher | 47 ++++++++++++++++++------------------------ lib/opcodes.py | 2 +- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/daemons/ganeti-watcher b/daemons/ganeti-watcher index 074fc3b34..94c6b48bb 100755 --- a/daemons/ganeti-watcher +++ b/daemons/ganeti-watcher @@ -74,28 +74,6 @@ def Indent(s, prefix='| '): return "%s%s\n" % (prefix, ('\n' + prefix).join(s.splitlines())) -def DoCmd(cmd): - """Run a shell command. - - Args: - cmd: the command to run. - - Raises CommandError with verbose commentary on error. - - """ - res = utils.RunCmd(cmd) - - if res.failed: - msg = ("Command %s failed:\n%s\nstdout:\n%sstderr:\n%s" % - (repr(cmd), - Indent(res.fail_reason), - Indent(res.stdout), - Indent(res.stderr))) - raise errors.CommandError(msg) - - return res - - class WatcherState(object): """Interface to a state file recording restart attempts. @@ -399,10 +377,24 @@ class Watcher(object): """Run gnt-cluster verify-disks. """ - # TODO: What should we do here? - result = DoCmd(['gnt-cluster', 'verify-disks']) - if result.output: - logging.info(result.output) + op = opcodes.OpVerifyDisks() + result = cli.SubmitOpCode(op, cl=client) + if not isinstance(result, (tuple, list)): + logging.error("Can't get a valid result from verify-disks") + return + offline_disk_instances = result[2] + if not offline_disk_instances: + # nothing to do + return + logging.debug("Will activate disks for instances %s", + ", ".join(offline_disk_instances)) + # we submit only one job, and wait for it. not optimal, but spams + # less the job queue + job = [opcodes.OpActivateInstanceDisks(instance_name=name) + for name in offline_disk_instances] + job_id = cli.SendJob(job, cl=client) + + cli.PollJob(job_id, cl=client, feedback_fn=logging.debug) def ParseOptions(): @@ -432,7 +424,8 @@ def main(): options, args = ParseOptions() - logger.SetupLogging(constants.LOG_WATCHER, debug=options.debug) + logger.SetupLogging(constants.LOG_WATCHER, debug=options.debug, + stderr_logging=options.debug) try: client = cli.GetClient() diff --git a/lib/opcodes.py b/lib/opcodes.py index 689ccb468..fda1f6d8e 100644 --- a/lib/opcodes.py +++ b/lib/opcodes.py @@ -207,7 +207,7 @@ class OpVerifyDisks(OpCode): Parameters: none - Result: two lists: + Result: a tuple of four elements: - list of node names with bad data returned (unreachable, etc.) - dict of node names with broken volume groups (values: error msg) - list of instances with degraded disks (that should be activated) -- GitLab