~hazmat/pyjuju/proposed-support

« back to all changes in this revision

Viewing changes to juju/agents/tests/test_unit.py

  • Committer: kapil.thangavelu at canonical
  • Date: 2012-05-22 22:08:15 UTC
  • mfrom: (484.1.53 trunk)
  • Revision ID: kapil.thangavelu@canonical.com-20120522220815-acyt8m89i9ybe0w1
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
643
643
        self.assertEquals(
644
644
            (yield self.states["unit"].get_charm_id()), old_charm_id)
645
645
 
646
 
 
647
646
    @inlineCallbacks
648
647
    def test_agent_upgrade_bad_unit_state(self):
649
648
        """The upgrade fails if the unit is in a bad state."""
673
672
            (yield self.states["unit"].get_charm_id()), old_charm_id)
674
673
 
675
674
    @inlineCallbacks
 
675
    def test_agent_force_upgrade_bad_unit_state(self):
 
676
        """The upgrade runs if forced and the unit is in a bad state."""
 
677
        # Upload a new version of the unit's charm
 
678
        repository = self.increment_charm(self.charm)
 
679
        charm = yield repository.find(CharmURL.parse("local:series/mysql"))
 
680
        charm, charm_state = yield self.publish_charm(charm.path)
 
681
        old_charm_id = yield self.states["unit"].get_charm_id()
 
682
 
 
683
        output = self.capture_logging("juju.agents.unit", level=logging.DEBUG)
 
684
 
 
685
        self.agent.set_watch_enabled(True)
 
686
        yield self.agent.startService()
 
687
 
 
688
        # Mark the unit for upgrade, with an invalid state.
 
689
        with (yield self.agent.workflow.lock()):
 
690
            yield self.agent.workflow.fire_transition("error_configure")
 
691
        yield self.states["service"].set_charm_id(charm_state.id)
 
692
        yield self.states["unit"].set_upgrade_flag(force=True)
 
693
 
 
694
        # Its hard to watch something with no hooks and no state changes.
 
695
        yield self.sleep(0.1)
 
696
 
 
697
        self.assertIdentical(
 
698
            (yield self.states["unit"].get_upgrade_flag()), False)
 
699
        self.assertIn("Forced upgrade complete", output.getvalue())
 
700
        self.assertEquals(
 
701
            (yield self.states["unit"].get_charm_id()), "local:series/mysql-2")
 
702
        self.assertEquals(old_charm_id, "local:series/dummy-1")
 
703
 
 
704
    @inlineCallbacks
676
705
    def test_agent_upgrade_no_flag(self):
677
706
        """An upgrade stops if there is no upgrade flag set."""
678
707
        log_written = self.wait_for_log(