Interdiff:

diff --git a/lib/cmdlib/base.py b/lib/cmdlib/base.py
index f52264c..97cafbd 100644
--- a/lib/cmdlib/base.py
+++ b/lib/cmdlib/base.py
@@ -294,8 +294,9 @@ class LogicalUnit(object):
     @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 wih HooksCallBack we ignore the could be a function
+    # For consistency wih HooksCallBack we ignore the "could be a function"
     # warning
     # pylint: disable=R0201
     return post_hook_node_uuids


On Tue, Mar 4, 2014 at 10:24 AM, Jose A. Lopes <[email protected]> wrote:

> On Mar 04 10:10, Michele Tartara wrote:
> > On Tue, Mar 4, 2014 at 8:18 AM, Thomas Thrainer <[email protected]>
> wrote:
> > > 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: Thomas Thrainer <[email protected]>
> > > ---
> > >  lib/backend.py     |  2 +-
> > >  lib/cmdlib/base.py | 26 ++++++++++++++++++++++++++
> > >  lib/hooksmaster.py | 15 ++++++++++++---
> > >  3 files changed, 39 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/lib/backend.py b/lib/backend.py
> > > index 558610b..6aac4e1 100644
> > > --- a/lib/backend.py
> > > +++ b/lib/backend.py
> > > @@ -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(),
> > >                                     cfg.GetMasterNode())
> > >        hm.RunPhase(constants.HOOKS_PHASE_PRE)
> > > diff --git a/lib/cmdlib/base.py b/lib/cmdlib/base.py
> > > index 46f5a37..1738fa0 100644
> > > --- a/lib/cmdlib/base.py
> > > +++ b/lib/cmdlib/base.py
> > > @@ -283,6 +283,26 @@ 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.
> > > +    """
> >
> > Missing newline before """: the style police will shout at you :-)
> >
> >
> > > +    # For consistency wih HooksCallBack we ignore the could be a
> function
> > > +    # warning
>
> This sentence needs revising.
>
> > > +    # 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 +421,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.
> > > diff --git a/lib/hooksmaster.py b/lib/hooksmaster.py
> > > index 515a2a8..1d4c351 100644
> > > --- a/lib/hooksmaster.py
> > > +++ b/lib/hooksmaster.py
> > > @@ -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
> > >        keys
> > >      @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)
> > >      else:
> > >        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)
> > > --
> > > 1.9.0.279.gdc9e3eb
> > >
> >
> > Rest LGTM, thanks.
> >
> > Michele
> >
> > --
> > Google Germany GmbH
> > Dienerstr. 12
> > 80331 München
> >
> > Registergericht und -nummer: Hamburg, HRB 86891
> > Sitz der Gesellschaft: Hamburg
> > Geschäftsführer: Graham Law, Christine Elizabeth Flores
>
> --
> Jose Antonio Lopes
> Ganeti Engineering
> Google Germany GmbH
> Dienerstr. 12, 80331, München
>
> Registergericht und -nummer: Hamburg, HRB 86891
> Sitz der Gesellschaft: Hamburg
> Geschäftsführer: Graham Law, Christine Elizabeth Flores
> Steuernummer: 48/725/00206
> Umsatzsteueridentifikationsnummer: DE813741370
>



-- 
Thomas Thrainer | Software Engineer | [email protected] |

Google Germany GmbH
Dienerstr. 12
80331 München

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores

Reply via email to