From 1fce5219fe23f75a35833036d7fa3fb8fb13c9d0 Mon Sep 17 00:00:00 2001 From: Guido Trotter Date: Wed, 30 Apr 2008 09:29:49 +0000 Subject: [PATCH] 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 --- lib/cmdlib.py | 18 ++++++++++++++++++ lib/mcpu.py | 16 ++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 1b56985..c241dad 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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. diff --git a/lib/mcpu.py b/lib/mcpu.py index 228465b..6411df5 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -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): -- 1.7.10.4