Commit d8fff41c authored by Guido Trotter's avatar Guido Trotter
Browse files

Add cluster-verify hooks

Only post-hooks are run on cluster verify, and then their output is sent back
to the LU, which upon failure displays it to the user and changes the result of
the execution to a failure.

Reviewed-by: iustinp
parent 1fce5219
...@@ -606,10 +606,12 @@ class LUDestroyCluster(NoHooksLU): ...@@ -606,10 +606,12 @@ class LUDestroyCluster(NoHooksLU):
rpc.call_node_leave_cluster(master) rpc.call_node_leave_cluster(master)
class LUVerifyCluster(NoHooksLU): class LUVerifyCluster(LogicalUnit):
"""Verifies the cluster status. """Verifies the cluster status.
""" """
HPATH = "cluster-verify"
HTYPE = constants.HTYPE_CLUSTER
_OP_REQP = ["skip_checks"] _OP_REQP = ["skip_checks"]
def _VerifyNode(self, node, file_list, local_cksum, vglist, node_result, def _VerifyNode(self, node, file_list, local_cksum, vglist, node_result,
...@@ -791,6 +793,18 @@ class LUVerifyCluster(NoHooksLU): ...@@ -791,6 +793,18 @@ class LUVerifyCluster(NoHooksLU):
if not constants.VERIFY_OPTIONAL_CHECKS.issuperset(self.skip_set): if not constants.VERIFY_OPTIONAL_CHECKS.issuperset(self.skip_set):
raise errors.OpPrereqError("Invalid checks to be skipped specified") raise errors.OpPrereqError("Invalid checks to be skipped specified")
def BuildHooksEnv(self):
"""Build hooks env.
Cluster-Verify hooks just rone in the post phase and their failure makes
the output be logged in the verify output and the verification to fail.
"""
all_nodes = self.cfg.GetNodeList()
# TODO: populate the environment with useful information for verify hooks
env = {}
return env, [], all_nodes
def Exec(self, feedback_fn): def Exec(self, feedback_fn):
"""Verify integrity of cluster, performing various test on nodes. """Verify integrity of cluster, performing various test on nodes.
...@@ -950,6 +964,47 @@ class LUVerifyCluster(NoHooksLU): ...@@ -950,6 +964,47 @@ class LUVerifyCluster(NoHooksLU):
return int(bad) return int(bad)
def HooksCallBack(self, phase, hooks_results, feedback_fn, lu_result):
"""Analize the post-hooks' result, handle it, and send some
nicely-formatted feedback back to the user.
Args:
phase: the hooks phase that has just been run
hooks_results: the results of the multi-node hooks rpc call
feedback_fn: function to send feedback back to the caller
lu_result: previous Exec result
"""
# We only really run POST phase hooks, and are only interested in their results
if phase == constants.HOOKS_PHASE_POST:
# Used to change hooks' output to proper indentation
indent_re = re.compile('^', re.M)
feedback_fn("* Hooks Results")
if not hooks_results:
feedback_fn(" - ERROR: general communication failure")
lu_result = 1
else:
for node_name in hooks_results:
show_node_header = True
res = hooks_results[node_name]
if res is False or not isinstance(res, list):
feedback_fn(" Communication failure")
lu_result = 1
continue
for script, hkr, output in res:
if hkr == constants.HKR_FAIL:
# The node header is only shown once, if there are
# failing hooks on that node
if show_node_header:
feedback_fn(" Node %s:" % node_name)
show_node_header = False
feedback_fn(" ERROR: Script %s failed, output:" % script)
output = indent_re.sub(' ', output)
feedback_fn("%s" % output)
lu_result = 1
return lu_result
class LUVerifyDisks(NoHooksLU): class LUVerifyDisks(NoHooksLU):
"""Verifies the cluster disks status. """Verifies the cluster disks status.
......
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