Revision b423c513

b/lib/mcpu.py
428 428
    self.lu = lu
429 429
    self.op = lu.op
430 430
    self.pre_env = None
431
    self.pre_nodes = None
431
    self.post_nodes = None
432 432

  
433 433
  def _BuildEnv(self, phase):
434 434
    """Compute the environment and the target nodes.
......
526 526
    (env, node_list_pre, node_list_post) = self._BuildEnv(phase)
527 527
    if nodes is None:
528 528
      if phase == constants.HOOKS_PHASE_PRE:
529
        self.pre_nodes = (node_list_pre, node_list_post)
530 529
        nodes = node_list_pre
530
        self.post_nodes = node_list_post
531
      elif self.post_nodes is None:
532
        raise AssertionError("Pre-phase must be run before post-phase")
531 533
      elif phase == constants.HOOKS_PHASE_POST:
532
        post_nodes = (node_list_pre, node_list_post)
533
        assert self.pre_nodes == post_nodes, \
534
               ("Node lists returned for post-phase hook don't match pre-phase"
535
                " lists (pre %s, post %s)" % (self.pre_nodes, post_nodes))
536
        nodes = node_list_post
534
        nodes = self.post_nodes
537 535
      else:
538 536
        raise AssertionError("Unknown phase '%s'" % phase)
539 537

  
b/test/ganeti.hooks_unittest.py
379 379
  def testConflict(self):
380 380
    for name in ["DATA_DIR", "OP_CODE"]:
381 381
      self.lu.hook_env = { name: "value" }
382

  
383
      # Test using a clean HooksMaster instance
384
      hm = mcpu.HooksMaster(self._HooksRpc, self.lu)
385

  
382 386
      for phase in [constants.HOOKS_PHASE_PRE, constants.HOOKS_PHASE_POST]:
383
        # Test using a clean HooksMaster instance
384
        self.assertRaises(AssertionError,
385
                          mcpu.HooksMaster(self._HooksRpc, self.lu).RunPhase,
386
                          phase)
387
        self.assertRaises(AssertionError, hm.RunPhase, phase)
387 388
        self.assertRaises(IndexError, self._rpcs.pop)
388 389

  
389 390
  def testNoNodes(self):
......
415 416
    self.assertRaises(AssertionError, self.hm.RunConfigUpdate)
416 417
    self.assertRaises(IndexError, self._rpcs.pop)
417 418

  
419
  def testNoPreBeforePost(self):
420
    self.lu.hook_env = {}
421
    self.assertRaises(AssertionError, self.hm.RunPhase,
422
                      constants.HOOKS_PHASE_POST)
423

  
418 424

  
419 425
if __name__ == '__main__':
420 426
  testutils.GanetiTestProgram()

Also available in: Unified diff