On Tue, Mar 4, 2014 at 8:18 AM, Thomas Thrainer <[email protected]> wrote:
> LUNodeAdd, the only LU using a node name still, is changed to overwrite
> PreparePostHookNodes() and use node UUIDs only as well.
> This allows to remove the support for 3-tuples as results of
> BuildHooksNodes() and removes the translation to node names.
>
> Fixes issue 742.
>
> Signed-off-by: Thomas Thrainer <[email protected]>
> ---
>  lib/cmdlib/base.py                 |  7 ++-----
>  lib/cmdlib/node.py                 |  5 ++++-
>  lib/hooksmaster.py                 | 11 +++--------
>  test/py/cmdlib/cluster_unittest.py |  2 +-
>  test/py/ganeti.hooks_unittest.py   | 16 +++++++++-------
>  5 files changed, 19 insertions(+), 22 deletions(-)
>
> diff --git a/lib/cmdlib/base.py b/lib/cmdlib/base.py
> index 1738fa0..f52264c 100644
> --- a/lib/cmdlib/base.py
> +++ b/lib/cmdlib/base.py
> @@ -269,13 +269,10 @@ class LogicalUnit(object):
>    def BuildHooksNodes(self):
>      """Build list of nodes to run LU's hooks.
>
> -    @rtype: tuple; (list, list) or (list, list, list)
> +    @rtype: tuple; (list, list)
>      @return: Tuple containing a list of node UUIDs on which the hook
>        should run before the execution and a list of node UUIDs on which the
> -      hook should run after the execution. As it might be possible that the
> -      node UUID is not known at the time this method is invoked, an optional
> -      third list can be added which contains node names on which the hook
> -      should run after the execution (in case of node add, for instance).
> +      hook should run after the execution.
>        No nodes should be returned as an empty list (and not None).
>      @note: If the C{HPATH} attribute of the LU class is C{None}, this 
> function
>        will not be called.
> diff --git a/lib/cmdlib/node.py b/lib/cmdlib/node.py
> index aa94860..41214f0 100644
> --- a/lib/cmdlib/node.py
> +++ b/lib/cmdlib/node.py
> @@ -138,7 +138,10 @@ class LUNodeAdd(LogicalUnit):
>        hook_nodes = list(set(hook_nodes) - set([new_node_info.uuid]))
>
>      # add the new node as post hook node by name; it does not have an UUID 
> yet
> -    return (hook_nodes, hook_nodes, [self.op.node_name, ])
> +    return (hook_nodes, hook_nodes)
> +
> +  def PreparePostHookNodes(self, post_hook_node_uuids):
> +    return post_hook_node_uuids + [self.new_node.uuid]
>
>    def CheckPrereq(self):
>      """Check prerequisites.
> diff --git a/lib/hooksmaster.py b/lib/hooksmaster.py
> index 1d4c351..23facd7 100644
> --- a/lib/hooksmaster.py
> +++ b/lib/hooksmaster.py
> @@ -268,15 +268,10 @@ class HooksMaster(object):
>        nodes = (None, None)
>      else:
>        hooks_nodes = lu.BuildHooksNodes()
> -      to_name = lambda node_uuids: frozenset(lu.cfg.GetNodeNames(node_uuids))
> -      if len(hooks_nodes) == 2:
> -        nodes = (to_name(hooks_nodes[0]), to_name(hooks_nodes[1]))
> -      elif len(hooks_nodes) == 3:
> -        nodes = (to_name(hooks_nodes[0]),
> -                 to_name(hooks_nodes[1]) | frozenset(hooks_nodes[2]))
> -      else:
> +      if len(hooks_nodes) != 2:
>          raise errors.ProgrammerError(
> -          "LogicalUnit.BuildHooksNodes must return a 2- or 3-tuple")
> +          "LogicalUnit.BuildHooksNodes must return a 2-tuple")
> +      nodes = (frozenset(hooks_nodes[0]), frozenset(hooks_nodes[1]))
>
>      master_name = cluster_name = None
>      if lu.cfg:
> diff --git a/test/py/cmdlib/cluster_unittest.py 
> b/test/py/cmdlib/cluster_unittest.py
> index 15e504f..cad1b4f 100644
> --- a/test/py/cmdlib/cluster_unittest.py
> +++ b/test/py/cmdlib/cluster_unittest.py
> @@ -234,7 +234,7 @@ class TestLUClusterPostInit(CmdlibTestCase):
>
>      self.ExecOpCode(op)
>
> -    self.assertSingleHooksCall([self.master.name],
> +    self.assertSingleHooksCall([self.master.uuid],
>                                 "cluster-init",
>                                 constants.HOOKS_PHASE_POST)
>
> diff --git a/test/py/ganeti.hooks_unittest.py 
> b/test/py/ganeti.hooks_unittest.py
> index d7cf32f..063b8f4 100755
> --- a/test/py/ganeti.hooks_unittest.py
> +++ b/test/py/ganeti.hooks_unittest.py
> @@ -495,7 +495,7 @@ class TestHooksRunnerEnv(unittest.TestCase):
>      assert isinstance(self.lu, FakeNoHooksLU), "LU was replaced"
>
>
> -class FakeEnvWithNodeNameLU(cmdlib.LogicalUnit):
> +class FakeEnvWithCustomPostHookNodesLU(cmdlib.LogicalUnit):
>    HPATH = "env_test_lu"
>    HTYPE = constants.HTYPE_GROUP
>
> @@ -506,7 +506,10 @@ class FakeEnvWithNodeNameLU(cmdlib.LogicalUnit):
>      return {}
>
>    def BuildHooksNodes(self):
> -    return (["a"], ["a"], ["explicit.node1.com", "explicit.node2.com"])
> +    return (["a"], ["a"])
> +
> +  def PreparePostHookNodes(self, post_hook_node_uuids):
> +    return post_hook_node_uuids + ["b"]
>
>
>  class TestHooksRunnerEnv(unittest.TestCase):
> @@ -514,7 +517,8 @@ class TestHooksRunnerEnv(unittest.TestCase):
>      self._rpcs = []
>
>      self.op = opcodes.OpTestDummy(result=False, messages=[], fail=False)
> -    self.lu = FakeEnvWithNodeNameLU(FakeProc(), self.op, FakeContext(), None)
> +    self.lu = FakeEnvWithCustomPostHookNodesLU(FakeProc(), self.op,
> +                                               FakeContext(), None)
>
>    def _HooksRpc(self, *args):
>      self._rpcs.append(args)
> @@ -526,15 +530,13 @@ class TestHooksRunnerEnv(unittest.TestCase):
>      hm.RunPhase(constants.HOOKS_PHASE_PRE)
>
>      (node_list, hpath, phase, env) = self._rpcs.pop(0)
> -    self.assertEqual(node_list, set(["node_a.example.com"]))
> +    self.assertEqual(node_list, set(["a"]))
>
>      # Check post-phase hook
>      hm.RunPhase(constants.HOOKS_PHASE_POST)
>
>      (node_list, hpath, phase, env) = self._rpcs.pop(0)
> -    self.assertEqual(node_list, set(["node_a.example.com",
> -                                     "explicit.node1.com",
> -                                     "explicit.node2.com"]))
> +    self.assertEqual(node_list, set(["a", "b"]))
>
>      self.assertRaises(IndexError, self._rpcs.pop)
>
> --
> 1.9.0.279.gdc9e3eb
>

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

Reply via email to