From b423c513369dbdb6512a5736771edee9eacfccc3 Mon Sep 17 00:00:00 2001 From: Michael Hanselmann <hansmi@google.com> Date: Thu, 17 Mar 2011 13:23:03 +0100 Subject: [PATCH] Remove restrictive hook node list check Commit dd7f67762 added a restrictive check for the node lists returned by BuildHooksEnv, leading to errors with some LUs, one of which was fixed in commit 0dfa2c227. As it turns out, other LUs have similar issues, some not easy to fix. This patch disables the restrictive check until the BuildHooksEnv functions can be split into one part generating the actual environment and one generating the node lists. Signed-off-by: Michael Hanselmann <hansmi@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/mcpu.py | 12 +++++------- test/ganeti.hooks_unittest.py | 14 ++++++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/mcpu.py b/lib/mcpu.py index 7ab7c18e6..399fcbe63 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -428,7 +428,7 @@ class HooksMaster(object): self.lu = lu self.op = lu.op self.pre_env = None - self.pre_nodes = None + self.post_nodes = None def _BuildEnv(self, phase): """Compute the environment and the target nodes. @@ -526,14 +526,12 @@ class HooksMaster(object): (env, node_list_pre, node_list_post) = self._BuildEnv(phase) if nodes is None: if phase == constants.HOOKS_PHASE_PRE: - self.pre_nodes = (node_list_pre, node_list_post) nodes = node_list_pre + self.post_nodes = node_list_post + elif self.post_nodes is None: + raise AssertionError("Pre-phase must be run before post-phase") elif phase == constants.HOOKS_PHASE_POST: - post_nodes = (node_list_pre, node_list_post) - assert self.pre_nodes == post_nodes, \ - ("Node lists returned for post-phase hook don't match pre-phase" - " lists (pre %s, post %s)" % (self.pre_nodes, post_nodes)) - nodes = node_list_post + nodes = self.post_nodes else: raise AssertionError("Unknown phase '%s'" % phase) diff --git a/test/ganeti.hooks_unittest.py b/test/ganeti.hooks_unittest.py index e9a1d4391..30836cd67 100755 --- a/test/ganeti.hooks_unittest.py +++ b/test/ganeti.hooks_unittest.py @@ -379,11 +379,12 @@ class TestHooksRunnerEnv(unittest.TestCase): def testConflict(self): for name in ["DATA_DIR", "OP_CODE"]: self.lu.hook_env = { name: "value" } + + # Test using a clean HooksMaster instance + hm = mcpu.HooksMaster(self._HooksRpc, self.lu) + for phase in [constants.HOOKS_PHASE_PRE, constants.HOOKS_PHASE_POST]: - # Test using a clean HooksMaster instance - self.assertRaises(AssertionError, - mcpu.HooksMaster(self._HooksRpc, self.lu).RunPhase, - phase) + self.assertRaises(AssertionError, hm.RunPhase, phase) self.assertRaises(IndexError, self._rpcs.pop) def testNoNodes(self): @@ -415,6 +416,11 @@ class TestHooksRunnerEnv(unittest.TestCase): self.assertRaises(AssertionError, self.hm.RunConfigUpdate) self.assertRaises(IndexError, self._rpcs.pop) + def testNoPreBeforePost(self): + self.lu.hook_env = {} + self.assertRaises(AssertionError, self.hm.RunPhase, + constants.HOOKS_PHASE_POST) + if __name__ == '__main__': testutils.GanetiTestProgram() -- GitLab