def test_agent_upgrade(self): """The agent can succesfully upgrade its charm.""" self.agent.set_watch_enabled(False) yield self.agent.startService() yield self.mark_charm_upgrade() hook_done = self.wait_on_hook( "upgrade-charm", executor=self.agent.executor) self.write_hook("upgrade-charm", "#!/bin/bash\nexit 0") output = self.capture_logging("unit.upgrade", level=logging.DEBUG) # Do the upgrade upgrade = CharmUpgradeOperation(self.agent) value = yield upgrade.run() # Verify the upgrade. self.assertIdentical(value, True) self.assertIn("Unit upgraded", output.getvalue()) yield hook_done new_charm = get_charm_from_path( os.path.join(self.agent.unit_directory, "charm")) self.assertEqual( self.charm.get_revision() + 1, new_charm.get_revision())
def test_agent_upgrade(self): """The agent can succesfully upgrade its charm.""" self.agent.set_watch_enabled(False) yield self.agent.startService() yield self.mark_charm_upgrade() hook_done = self.wait_on_hook("upgrade-charm", executor=self.agent.executor) self.write_hook("upgrade-charm", "#!/bin/bash\nexit 0") output = self.capture_logging("unit.upgrade", level=logging.DEBUG) # Do the upgrade upgrade = CharmUpgradeOperation(self.agent) value = yield upgrade.run() # Verify the upgrade. self.assertIdentical(value, True) self.assertIn("Unit upgraded", output.getvalue()) yield hook_done new_charm = get_charm_from_path( os.path.join(self.agent.unit_directory, "charm")) self.assertEqual(self.charm.get_revision() + 1, new_charm.get_revision())
def setUp(self): yield super(UnitContainerDeploymentTest, self).setUp() self.juju_home = self.makeDir() # Setup unit namespace environ = dict(os.environ) environ["JUJU_UNIT_NS"] = "ns1" self.change_environment(**environ) self.unit_deploy = UnitContainerDeployment(self.unit_name, self.juju_home) self.charm = get_charm_from_path(self.sample_dir1) self.bundle = self.charm.as_bundle() self.output = self.capture_logging("unit.deploy", level=logging.DEBUG)
def test_unpack_charm(self): """ The deployment unpacks a charm bundle into the unit workspace. """ self.deployment.unpack_charm(self.bundle) unit_path = os.path.join(self.units_directory, self.unit_name.replace("/", "-")) self.assertTrue(os.path.exists(unit_path)) charm_path = os.path.join(unit_path, "charm") self.assertTrue(os.path.exists(charm_path)) charm = get_charm_from_path(charm_path) self.assertEqual(charm.get_revision(), self.charm.get_revision())
def setUp(self): yield super(UnitContainerDeploymentTest, self).setUp() self.juju_home = self.makeDir() # Setup unit namespace environ = dict(os.environ) environ["JUJU_UNIT_NS"] = "ns1" self.change_environment(**environ) self.unit_deploy = UnitContainerDeployment( self.unit_name, self.juju_home) self.charm = get_charm_from_path(self.sample_dir1) self.bundle = self.charm.as_bundle() self.output = self.capture_logging("unit.deploy", level=logging.DEBUG)
def setUp(self): super(UnitMachineDeploymentTest, self).setUp() self.charm = get_charm_from_path(self.sample_dir1) self.bundle = self.charm.as_bundle() self.juju_directory = self.makeDir() self.units_directory = os.path.join(self.juju_directory, "units") os.mkdir(self.units_directory) self.unit_name = "wordpress/0" self.deployment = UnitMachineDeployment(self.unit_name, self.juju_directory) self.assertEqual(self.deployment.unit_agent_module, "juju.agents.unit") self.deployment.unit_agent_module = "juju.agents.dummy"
def test_unpack_charm(self): """ The deployment unpacks a charm bundle into the unit workspace. """ self.deployment.unpack_charm(self.bundle) unit_path = os.path.join( self.units_directory, self.unit_name.replace("/", "-")) self.assertTrue(os.path.exists(unit_path)) charm_path = os.path.join(unit_path, "charm") self.assertTrue(os.path.exists(charm_path)) charm = get_charm_from_path(charm_path) self.assertEqual( charm.get_revision(), self.charm.get_revision())
def setUp(self): super(UnitMachineDeploymentTest, self).setUp() self.charm = get_charm_from_path(self.sample_dir1) self.bundle = self.charm.as_bundle() self.juju_directory = self.makeDir() self.units_directory = os.path.join(self.juju_directory, "units") os.mkdir(self.units_directory) self.unit_name = "wordpress/0" self.deployment = UnitMachineDeployment( self.unit_name, self.juju_directory) self.assertEqual( self.deployment.unit_agent_module, "juju.agents.unit") self.deployment.unit_agent_module = "juju.agents.dummy"
def test_agent_upgrade(self): """The agent can succesfully upgrade its charm.""" log_written = self.wait_for_log("juju.agents.unit", "Upgrade complete") hook_done = self.wait_on_hook( "upgrade-charm", executor=self.agent.executor) self.agent.set_watch_enabled(True) yield self.agent.startService() yield self.mark_charm_upgrade() yield hook_done yield log_written self.assertIdentical( (yield self.states["unit"].get_upgrade_flag()), False) new_charm = get_charm_from_path( os.path.join(self.agent.unit_directory, "charm")) self.assertEqual( self.charm.get_revision() + 1, new_charm.get_revision())
def test_agent_upgrade_hook_failure(self): """An upgrade fails if the upgrade hook errors.""" self.agent.set_watch_enabled(False) yield self.agent.startService() # Upload a new version of the unit's charm repository = self.increment_charm(self.charm) charm = yield repository.find(CharmURL.parse("local:series/mysql")) charm, charm_state = yield self.publish_charm(charm.path) # Mark the unit for upgrade yield self.states["service"].set_charm_id(charm_state.id) yield self.states["unit"].set_upgrade_flag() hook_done = self.wait_on_hook("upgrade-charm", executor=self.agent.executor) self.write_hook("upgrade-charm", "#!/bin/bash\nexit 1") output = self.capture_logging("unit.upgrade", level=logging.DEBUG) # Do the upgrade upgrade = CharmUpgradeOperation(self.agent) value = yield upgrade.run() # Verify the failed upgrade. self.assertIdentical(value, False) self.assertIn("Invoking upgrade transition", output.getvalue()) self.assertIn("Upgrade failed.", output.getvalue()) yield hook_done # Verify state workflow_state = yield self.agent.workflow.get_state() self.assertEqual("charm_upgrade_error", workflow_state) # Verify new charm is in place new_charm = get_charm_from_path( os.path.join(self.agent.unit_directory, "charm")) self.assertEqual(self.charm.get_revision() + 1, new_charm.get_revision()) # Verify upgrade flag is cleared. self.assertFalse((yield self.states["unit"].get_upgrade_flag()))
def test_agent_upgrade_hook_failure(self): """An upgrade fails if the upgrade hook errors.""" self.agent.set_watch_enabled(False) yield self.agent.startService() # Upload a new version of the unit's charm repository = self.increment_charm(self.charm) charm = yield repository.find(CharmURL.parse("local:series/mysql")) charm, charm_state = yield self.publish_charm(charm.path) # Mark the unit for upgrade yield self.states["service"].set_charm_id(charm_state.id) yield self.states["unit"].set_upgrade_flag() hook_done = self.wait_on_hook( "upgrade-charm", executor=self.agent.executor) self.write_hook("upgrade-charm", "#!/bin/bash\nexit 1") output = self.capture_logging("unit.upgrade", level=logging.DEBUG) # Do the upgrade upgrade = CharmUpgradeOperation(self.agent) value = yield upgrade.run() # Verify the failed upgrade. self.assertIdentical(value, False) self.assertIn("Invoking upgrade transition", output.getvalue()) self.assertIn("Upgrade failed.", output.getvalue()) yield hook_done # Verify state workflow_state = yield self.agent.workflow.get_state() self.assertEqual("charm_upgrade_error", workflow_state) # Verify new charm is in place new_charm = get_charm_from_path( os.path.join(self.agent.unit_directory, "charm")) self.assertEqual( self.charm.get_revision() + 1, new_charm.get_revision()) # Verify upgrade flag is cleared. self.assertFalse((yield self.states["unit"].get_upgrade_flag()))
def publish_charm(self, charm_path=sample_directory): charm = get_charm_from_path(charm_path) publisher = CharmPublisher(self.client, self.storage) yield publisher.add_charm(local_charm_id(charm), charm) charm_states = yield publisher.publish() returnValue((charm, charm_states[0]))
def bundle_in_place(url, local_path): # must keep ref to charm else temp file goes out of scope. charm = get_charm_from_path(sample_directory) bundle = charm.as_bundle() shutil.copyfile(bundle.path, local_path)