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_origin_usage(self): """The machine agent is started with a origin environment variable """ mock_container = self.mocker.patch(LXCContainer) mock_container.is_constructed() self.mocker.result(True) mock_container.is_constructed() self.mocker.result(True) self.mocker.replay() environ = dict(os.environ) environ["JUJU_ORIGIN"] = "lp:~juju/foobar" self.change_environment(**environ) unit_deploy = UnitContainerDeployment(self.unit_name, self.juju_home) container = yield unit_deploy._get_master_template( "local", "127.0.0.1:1", "abc") self.assertEqual(container.origin, "lp:~juju/foobar") self.assertEqual( container.customize_log, os.path.join(self.juju_home, "units", "master-customize.log"))
def test_origin_usage(self): """The machine agent is started with a origin environment variable """ mock_container = self.mocker.patch(LXCContainer) mock_container.is_constructed() self.mocker.result(True) mock_container.is_constructed() self.mocker.result(True) self.mocker.replay() environ = dict(os.environ) environ["JUJU_ORIGIN"] = "lp:~juju/foobar" self.change_environment(**environ) unit_deploy = UnitContainerDeployment( self.unit_name, self.juju_home) container = yield unit_deploy._get_master_template( "local", "127.0.0.1:1", "abc") self.assertEqual(container.origin, "lp:~juju/foobar") self.assertEqual( container.customize_log, os.path.join(self.juju_home, "units", "master-customize.log"))
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)
class UnitContainerDeploymentTest(RepositoryTestBase): unit_name = "riak/0" @inlineCallbacks 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 get_normalized(self, output): # strip python path for comparison return "\n".join(filter(None, output.split("\n"))[:-2]) def test_get_container_name(self): self.assertEqual("ns1-riak-0", self.unit_deploy.container_name) def test_get_upstart_job(self): upstart_job = self.unit_deploy.get_upstart_unit_job( 0, "127.0.1.1:2181") job = self.get_normalized(upstart_job) self.assertIn('JUJU_ZOOKEEPER="127.0.1.1:2181"', job) self.assertIn('JUJU_MACHINE_ID="0"', job) self.assertIn('JUJU_UNIT_NAME="riak/0"', job) @inlineCallbacks def test_destroy(self): mock_container = self.mocker.patch(self.unit_deploy.container) mock_container.destroy() self.mocker.replay() yield self.unit_deploy.destroy() output = self.output.getvalue() self.assertIn("Destroying container...", output) self.assertIn("Destroyed container for riak/0", output) @inlineCallbacks def test_origin_usage(self): """The machine agent is started with a origin environment variable """ mock_container = self.mocker.patch(LXCContainer) mock_container.is_constructed() self.mocker.result(True) mock_container.is_constructed() self.mocker.result(True) self.mocker.replay() environ = dict(os.environ) environ["JUJU_ORIGIN"] = "lp:~juju/foobar" self.change_environment(**environ) unit_deploy = UnitContainerDeployment(self.unit_name, self.juju_home) container = yield unit_deploy._get_master_template( "local", "127.0.0.1:1", "abc") self.assertEqual(container.origin, "lp:~juju/foobar") self.assertEqual( container.customize_log, os.path.join(self.juju_home, "units", "master-customize.log")) @inlineCallbacks def test_start(self): container = LXCContainer(self.unit_name, None, None, None) rootfs = self.makeDir() env = dict(os.environ) env["JUJU_PUBLIC_KEY"] = "dsa ..." self.change_environment(**env) mock_deploy = self.mocker.patch(self.unit_deploy) # this minimally validates that we are also called with the # expect public key mock_deploy._get_container(ANY, ANY, ANY, env["JUJU_PUBLIC_KEY"]) self.mocker.result((container, rootfs)) mock_container = self.mocker.patch(container) mock_container.run() self.mocker.replay() self.unit_deploy.directory = rootfs os.makedirs(os.path.join(rootfs, "etc", "init")) yield self.unit_deploy.start("0", "127.0.1.1:2181", self.bundle) # Verify the upstart job upstart_agent_name = "%s-unit-agent.conf" % (self.unit_name.replace( "/", "-")) content = open(os.path.join(rootfs, "etc", "init", upstart_agent_name)).read() job = self.get_normalized(content) self.assertIn('JUJU_ZOOKEEPER="127.0.1.1:2181"', job) self.assertIn('JUJU_MACHINE_ID="0"', job) self.assertIn('JUJU_UNIT_NAME="riak/0"', job) # Verify the symlink exists self.assertTrue( os.path.lexists( os.path.join(self.unit_deploy.juju_home, "units", self.unit_deploy.unit_path_name, "unit.log"))) # Verify the charm is on disk. self.assertTrue( os.path.exists( os.path.join(self.unit_deploy.directory, "var", "lib", "juju", "units", self.unit_deploy.unit_path_name, "charm", "metadata.yaml"))) # Verify the directory structure in the unit. self.assertTrue( os.path.exists( os.path.join(self.unit_deploy.directory, "var", "lib", "juju", "state"))) self.assertTrue( os.path.exists( os.path.join(self.unit_deploy.directory, "var", "log", "juju"))) # Verify log output output = self.output.getvalue() self.assertIn("Charm extracted into container", output) self.assertIn("Started container for %s" % self.unit_deploy.unit_name, output) @inlineCallbacks def test_get_container(self): rootfs = self.makeDir() container = LXCContainer(self.unit_name, None, None, None) mock_deploy = self.mocker.patch(self.unit_deploy) mock_deploy._get_master_template(ANY, ANY, ANY) self.mocker.result(container) mock_container = self.mocker.patch(container) mock_container.clone(ANY) self.mocker.result(container) self.mocker.replay() container, rootfs = yield self.unit_deploy._get_container( "0", "127.0.0.1:2181", None, "dsa...") output = self.output.getvalue() self.assertIn("Container created for %s" % self.unit_deploy.unit_name, output)
class UnitContainerDeploymentTest(RepositoryTestBase): unit_name = "riak/0" @inlineCallbacks 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 get_normalized(self, output): # strip python path for comparison return "\n".join(filter(None, output.split("\n"))[:-2]) def test_get_container_name(self): self.assertEqual( "ns1-riak-0", self.unit_deploy.container_name) def test_get_upstart_job(self): upstart_job = self.unit_deploy.get_upstart_unit_job( 0, "127.0.1.1:2181") job = self.get_normalized(upstart_job) self.assertIn('JUJU_ZOOKEEPER="127.0.1.1:2181"', job) self.assertIn('JUJU_MACHINE_ID="0"', job) self.assertIn('JUJU_UNIT_NAME="riak/0"', job) @inlineCallbacks def test_destroy(self): mock_container = self.mocker.patch(self.unit_deploy.container) mock_container.destroy() self.mocker.replay() yield self.unit_deploy.destroy() output = self.output.getvalue() self.assertIn("Destroying container...", output) self.assertIn("Destroyed container for riak/0", output) @inlineCallbacks def test_origin_usage(self): """The machine agent is started with a origin environment variable """ mock_container = self.mocker.patch(LXCContainer) mock_container.is_constructed() self.mocker.result(True) mock_container.is_constructed() self.mocker.result(True) self.mocker.replay() environ = dict(os.environ) environ["JUJU_ORIGIN"] = "lp:~juju/foobar" self.change_environment(**environ) unit_deploy = UnitContainerDeployment( self.unit_name, self.juju_home) container = yield unit_deploy._get_master_template( "local", "127.0.0.1:1", "abc") self.assertEqual(container.origin, "lp:~juju/foobar") self.assertEqual( container.customize_log, os.path.join(self.juju_home, "units", "master-customize.log")) @inlineCallbacks def test_start(self): container = LXCContainer(self.unit_name, None, None, None) rootfs = self.makeDir() env = dict(os.environ) env["JUJU_PUBLIC_KEY"] = "dsa ..." self.change_environment(**env) mock_deploy = self.mocker.patch(self.unit_deploy) # this minimally validates that we are also called with the # expect public key mock_deploy._get_container(ANY, ANY, ANY, env["JUJU_PUBLIC_KEY"]) self.mocker.result((container, rootfs)) mock_container = self.mocker.patch(container) mock_container.run() self.mocker.replay() self.unit_deploy.directory = rootfs os.makedirs(os.path.join(rootfs, "etc", "init")) yield self.unit_deploy.start("0", "127.0.1.1:2181", self.bundle) # Verify the upstart job upstart_agent_name = "%s-unit-agent.conf" % ( self.unit_name.replace("/", "-")) content = open( os.path.join(rootfs, "etc", "init", upstart_agent_name)).read() job = self.get_normalized(content) self.assertIn('JUJU_ZOOKEEPER="127.0.1.1:2181"', job) self.assertIn('JUJU_MACHINE_ID="0"', job) self.assertIn('JUJU_UNIT_NAME="riak/0"', job) # Verify the symlink exists self.assertTrue(os.path.lexists(os.path.join( self.unit_deploy.juju_home, "units", self.unit_deploy.unit_path_name, "unit.log"))) # Verify the charm is on disk. self.assertTrue(os.path.exists(os.path.join( self.unit_deploy.directory, "var", "lib", "juju", "units", self.unit_deploy.unit_path_name, "charm", "metadata.yaml"))) # Verify the directory structure in the unit. self.assertTrue(os.path.exists(os.path.join( self.unit_deploy.directory, "var", "lib", "juju", "state"))) self.assertTrue(os.path.exists(os.path.join( self.unit_deploy.directory, "var", "log", "juju"))) # Verify log output output = self.output.getvalue() self.assertIn("Charm extracted into container", output) self.assertIn("Started container for %s" % self.unit_deploy.unit_name, output) @inlineCallbacks def test_get_container(self): rootfs = self.makeDir() container = LXCContainer(self.unit_name, None, None, None) mock_deploy = self.mocker.patch(self.unit_deploy) mock_deploy._get_master_template(ANY, ANY, ANY) self.mocker.result(container) mock_container = self.mocker.patch(container) mock_container.clone(ANY) self.mocker.result(container) self.mocker.replay() container, rootfs = yield self.unit_deploy._get_container( "0", "127.0.0.1:2181", None, "dsa...") output = self.output.getvalue() self.assertIn("Container created for %s" % self.unit_deploy.unit_name, output)