def test_lxc_container(self): self.addCleanup(self.clean_container, DEFAULT_CONTAINER) customize_log = self.makeFile() c = LXCContainer(DEFAULT_CONTAINER, "dsa...", "precise", "ppa", customize_log=customize_log) running = yield c.is_running() self.assertFalse(running) self.assertFalse(c.is_constructed()) # verify we can't run a non-constructed container failure = c.run() yield self.assertFailure(failure, LXCError) yield c.create() self.assertFalse(running) self.assertTrue(c.is_constructed()) yield c.run() running = yield c.is_running() self.assertTrue(running) self.assertTrue(c.is_constructed()) output = _lxc_ls() self.assertIn(DEFAULT_CONTAINER, output) # Verify we have a path into the container self.assertTrue(os.path.exists(c.rootfs)) self.assertTrue(c.is_constructed()) self.verify_container(c, "dsa...", "precise", "ppa") # Verify that we are in containers containers = yield get_containers(None) self.assertEqual(containers[DEFAULT_CONTAINER], True) # tear it down yield c.destroy() running = yield c.is_running() self.assertFalse(running) containers = yield get_containers(None) self.assertNotIn(DEFAULT_CONTAINER, containers) # Verify the customize log file. self.assertTrue(os.path.exists(customize_log)) # and its gone output = _lxc_ls() self.assertNotIn(DEFAULT_CONTAINER, output)
def test_lxc_container(self): self.addCleanup(self.clean_container, DEFAULT_CONTAINER) customize_log = self.makeFile() c = LXCContainer( DEFAULT_CONTAINER, "dsa...", "ppa", customize_log=customize_log) running = yield c.is_running() self.assertFalse(running) self.assertFalse(c.is_constructed()) # verify we can't run a non-constructed container failure = c.run() yield self.assertFailure(failure, LXCError) yield c.create() self.assertFalse(running) self.assertTrue(c.is_constructed()) yield c.run() running = yield c.is_running() self.assertTrue(running) self.assertTrue(c.is_constructed()) output = _lxc_ls() self.assertIn(DEFAULT_CONTAINER, output) # verify we have a path into the container self.assertTrue(os.path.exists(c.rootfs)) self.assertTrue(c.is_constructed()) self.verify_container(c, "dsa...", "ppa") # verify that we are in containers containers = yield get_containers(None) self.assertEqual(containers[DEFAULT_CONTAINER], True) # tear it down yield c.destroy() running = yield c.is_running() self.assertFalse(running) containers = yield get_containers(None) self.assertNotIn(DEFAULT_CONTAINER, containers) # Verify the customize log file. self.assertTrue(os.path.exists(customize_log)) # and its gone output = _lxc_ls() self.assertNotIn(DEFAULT_CONTAINER, output)
def _get_master_template(self, machine_id, zookeeper_hosts, public_key): container_template_name = "%s-%s-template" % ( self._unit_namespace, machine_id) master_template = LXCContainer( container_template_name, origin=self._juju_origin, public_key=public_key) # Debug log for the customize script, customize is only run on master. customize_log_path = os.path.join( self.juju_home, "units", "master-customize.log") master_template.customize_log = customize_log_path if not master_template.is_constructed(): log.debug("Creating master container...") yield master_template.create() log.debug("Created master container %s" % container_template_name) # it wasn't constructed and we couldn't construct it if not master_template.is_constructed(): raise LXCError("Unable to create master container") returnValue(master_template)
def _get_master_template(self, machine_id, zookeeper_hosts, public_key): container_template_name = "%s-%s-template" % (self._unit_namespace, machine_id) master_template = LXCContainer(container_template_name, origin=self._juju_origin, public_key=public_key) # Debug log for the customize script, customize is only run on master. customize_log_path = os.path.join(self.juju_home, "units", "master-customize.log") master_template.customize_log = customize_log_path if not master_template.is_constructed(): log.debug("Creating master container...") yield master_template.create() log.debug("Created master container %s" % container_template_name) # it wasn't constructed and we couldn't construct it if not master_template.is_constructed(): raise LXCError("Unable to create master container") returnValue(master_template)