Commit 1fce5219 authored by Guido Trotter's avatar Guido Trotter

Add a LU Hooks notification function

Previously LUs could be failed by pre-hooks, and post-hooks just had effects by
themselves. This patch allows a LU to define the HooksCallBack function if it
wants to know about its hooks' results and alter its results in response.

The ChainOpCode execution path contains some commented out hooks code, which
this patch modifies to run the HooksCallBack function, so this is not forgot if
it ever gets uncommented out.

Reviewed-by: iustinp
parent b07a6922
......@@ -153,6 +153,24 @@ class LogicalUnit(object):
"""
raise NotImplementedError
def HooksCallBack(self, phase, hook_results, feedback_fn, lu_result):
"""Notify the LU about the results of its hooks.
This method is called every time a hooks phase is executed, and notifies
the Logical Unit about the hooks' result. The LU can then use it to alter
its result based on the hooks. By default the method does nothing and the
previous result is passed back unchanged but any LU can define it if it
wants to use the local cluster hook-scripts somehow.
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: the previous result this LU had, or None in the PRE phase.
"""
return lu_result
class NoHooksLU(LogicalUnit):
"""Simple LU which runs no hooks.
......
......@@ -127,10 +127,14 @@ class Processor(object):
lu = lu_class(self, op, self.cfg, self.sstore)
lu.CheckPrereq()
hm = HooksMaster(rpc.call_hooks_runner, self, lu)
hm.RunPhase(constants.HOOKS_PHASE_PRE)
h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE)
lu.HooksCallBack(constants.HOOKS_PHASE_PRE,
h_results, self._feedback_fn, None)
try:
result = lu.Exec(self._feedback_fn)
hm.RunPhase(constants.HOOKS_PHASE_POST)
h_results = hm.RunPhase(constants.HOOKS_PHASE_POST)
result = lu.HooksCallBack(constants.HOOKS_PHASE_POST,
h_results, self._feedback_fn, result)
finally:
if lu.cfg is not None:
# we use lu.cfg and not self.cfg as for init cluster, self.cfg
......@@ -166,10 +170,14 @@ class Processor(object):
lu.CheckPrereq()
#if do_hooks:
# hm = HooksMaster(rpc.call_hooks_runner, self, lu)
# hm.RunPhase(constants.HOOKS_PHASE_PRE)
# h_results = hm.RunPhase(constants.HOOKS_PHASE_PRE)
# lu.HooksCallBack(constants.HOOKS_PHASE_PRE,
# h_results, self._feedback_fn, None)
result = lu.Exec(self._feedback_fn)
#if do_hooks:
# hm.RunPhase(constants.HOOKS_PHASE_POST)
# h_results = hm.RunPhase(constants.HOOKS_PHASE_POST)
# result = lu.HooksCallBack(constants.HOOKS_PHASE_POST,
# h_results, self._feedback_fn, result)
return result
def LogStep(self, current, total, message):
......
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