Skip to content
Snippets Groups Projects
Commit 5188ab37 authored by Iustin Pop's avatar Iustin Pop
Browse files

Remove last use of utils.RunCmd from the watcher

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
parent 36b8c2c1
No related merge requests found
......@@ -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()
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment