+ self.lu.hook_env = {
+ "FOO": "value",
+ }
+
+ hm = mcpu.HooksMaster.BuildFromLu(self._HooksRpc, self.lu)
+ hm.RunPhase(constants.HOOKS_PHASE_POST)
+
+ (node_list, hpath, phase, env) = self._rpcs.pop(0)
+ self.assertEqual(node_list, set(["localhost"]))
+ self.assertEqual(hpath, self.lu.HPATH)
+ self.assertEqual(phase, constants.HOOKS_PHASE_POST)
+ self.assertEqual(env["GANETI_FOO"], "value")
+ self.assertEqual(env["GANETI_POST_FOO"], "value")
+ self._CheckEnv(env, constants.HOOKS_PHASE_POST, self.lu.HPATH)
+
+ self.assertRaises(IndexError, self._rpcs.pop)
+
+ def testNoHooksLU(self):
+ self.lu = FakeNoHooksLU(FakeProc(), self.op, FakeContext(), None)
+ self.assertRaises(AssertionError, self.lu.BuildHooksEnv)
+ self.assertRaises(AssertionError, self.lu.BuildHooksNodes)
+
+ hm = mcpu.HooksMaster.BuildFromLu(self._HooksRpc, self.lu)
+ self.assertEqual(hm.pre_env, {})
+ self.assertRaises(IndexError, self._rpcs.pop)
+
+ hm.RunPhase(constants.HOOKS_PHASE_PRE)
+ self.assertRaises(IndexError, self._rpcs.pop)
+
+ hm.RunPhase(constants.HOOKS_PHASE_POST)
+ self.assertRaises(IndexError, self._rpcs.pop)
+
+ hm.RunConfigUpdate()
+
+ (node_list, hpath, phase, env) = self._rpcs.pop(0)
+ self.assertEqual(set(node_list), set([self.lu.cfg.GetMasterNode()]))
+ self.assertEqual(hpath, constants.HOOKS_NAME_CFGUPDATE)
+ self.assertEqual(phase, constants.HOOKS_PHASE_POST)
+ self.assertFalse(compat.any(key.startswith("GANETI_POST") for key in env))
+ self._CheckEnv(env, constants.HOOKS_PHASE_POST,
+ constants.HOOKS_NAME_CFGUPDATE)
+ self.assertRaises(IndexError, self._rpcs.pop)
+
+ assert isinstance(self.lu, FakeNoHooksLU), "LU was replaced"