Remove restrictive hook node list check
authorMichael Hanselmann <hansmi@google.com>
Thu, 17 Mar 2011 12:23:03 +0000 (13:23 +0100)
committerMichael Hanselmann <hansmi@google.com>
Thu, 17 Mar 2011 16:43:31 +0000 (17:43 +0100)
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
test/ganeti.hooks_unittest.py

index 7ab7c18..399fcbe 100644 (file)
@@ -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)
 
index e9a1d43..30836cd 100755 (executable)
@@ -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()