Commit 237a833c authored by Thomas Thrainer's avatar Thomas Thrainer
Browse files

Add PreparePostHookNodes to LUs

This method can be used to alter the list of node UUIDs on which post
hooks are executed. PreparePostHookNodes is called after Exec, so LUs
can use data only known after the execution of the LU.
Signed-off-by: default avatarThomas Thrainer <>
Reviewed-by: default avatarMichele Tartara <>
parent 510f672f
......@@ -332,7 +332,7 @@ def RunLocalHooks(hook_opcode, hooks_path, env_builder_fn):
cfg = _GetConfig()
hr = HooksRunner()
hm = hooksmaster.HooksMaster(hook_opcode, hooks_path, nodes,
hr.RunLocalHooks, None, env_fn,
hr.RunLocalHooks, None, env_fn, None,
logging.warning, cfg.GetClusterName(),
......@@ -283,6 +283,27 @@ class LogicalUnit(object):
raise NotImplementedError
def PreparePostHookNodes(self, post_hook_node_uuids):
"""Extend list of nodes to run the post LU hook.
This method allows LUs to change the list of node UUIDs on which the
post hook should run after the LU has been executed but before the post
hook is run.
@type post_hook_node_uuids: list
@param post_hook_node_uuids: The initial list of node UUIDs to run the
post hook on, as returned by L{BuildHooksNodes}.
@rtype: list
@return: list of node UUIDs on which the post hook should run. The default
implementation returns the passed in C{post_hook_node_uuids}, but
custom implementations can choose to alter the list.
# For consistency with HooksCallBack we ignore the "could be a function"
# warning
# pylint: disable=R0201
return post_hook_node_uuids
def HooksCallBack(self, phase, hook_results, feedback_fn, lu_result):
"""Notify the LU about the results of its hooks.
......@@ -401,6 +422,12 @@ class NoHooksLU(LogicalUnit): # pylint: disable=W0223
raise AssertionError("BuildHooksNodes called for NoHooksLU")
def PreparePostHookNodes(self, post_hook_node_uuids):
"""Empty PreparePostHookNodes for NoHooksLU.
raise AssertionError("PreparePostHookNodes called for NoHooksLU")
class Tasklet:
"""Tasklet base class.
......@@ -46,8 +46,8 @@ def _RpcResultsToHooksResults(rpc_results):
class HooksMaster(object):
def __init__(self, opcode, hooks_path, nodes, hooks_execution_fn,
hooks_results_adapt_fn, build_env_fn, log_fn, htype=None,
cluster_name=None, master_name=None):
hooks_results_adapt_fn, build_env_fn, prepare_post_nodes_fn,
log_fn, htype=None, cluster_name=None, master_name=None):
"""Base class for hooks masters.
This class invokes the execution of hooks according to the behaviour
......@@ -70,6 +70,11 @@ class HooksMaster(object):
@type build_env_fn: function that returns a dictionary having strings as
@param build_env_fn: function that builds the environment for the hooks
@type prepare_post_nodes_fn: function that take a list of node UUIDs and
returns a list of node UUIDs
@param prepare_post_nodes_fn: function that is invoked right before
executing post hooks and can change the list of node UUIDs to run the post
hooks on
@type log_fn: function that accepts a string
@param log_fn: logging function
@type htype: string or None
......@@ -86,6 +91,7 @@ class HooksMaster(object):
self.hooks_execution_fn = hooks_execution_fn
self.hooks_results_adapt_fn = hooks_results_adapt_fn
self.build_env_fn = build_env_fn
self.prepare_post_nodes_fn = prepare_post_nodes_fn
self.log_fn = log_fn
self.htype = htype
self.cluster_name = cluster_name
......@@ -195,6 +201,8 @@ class HooksMaster(object):
elif phase == constants.HOOKS_PHASE_POST:
if node_names is None:
node_names = self.post_nodes
if node_names is not None and self.prepare_post_nodes_fn is not None:
node_names = frozenset(self.prepare_post_nodes_fn(list(node_names)))
env = self._BuildEnv(phase)
raise AssertionError("Unknown phase '%s'" % phase)
......@@ -277,4 +285,5 @@ class HooksMaster(object):
return HooksMaster(lu.op.OP_ID, lu.HPATH, nodes, hooks_execution_fn,
_RpcResultsToHooksResults, lu.BuildHooksEnv,
lu.LogWarning, lu.HTYPE, cluster_name, master_name)
lu.PreparePostHookNodes, lu.LogWarning, lu.HTYPE,
cluster_name, master_name)
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