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 test_container_clone(self): self.addCleanup(self.clean_container, DEFAULT_CONTAINER) self.addCleanup(self.clean_container, DEFAULT_CONTAINER + "_child") master_container = LXCContainer(DEFAULT_CONTAINER, origin="ppa", public_key="dsa...", series="oneiric") # verify that we cannot clone an unconstructed container failure = master_container.clone("test_lxc_fail") yield self.assertFailure(failure, LXCError) yield master_container.create() # Clone a child container from the template child_name = DEFAULT_CONTAINER + "_child" c = yield master_container.clone(child_name) self.assertEqual(c.container_name, child_name) running = yield c.is_running() self.assertFalse(running) yield c.run() running = yield c.is_running() self.assertTrue(running) output = _lxc_ls() self.assertIn(DEFAULT_CONTAINER, output) self.verify_container(c, "dsa...", "oneiric", "ppa") # verify that we are in containers containers = yield get_containers(None) self.assertEqual(containers[child_name], True) # tear it down yield c.destroy() running = yield c.is_running() self.assertFalse(running) containers = yield get_containers(None) self.assertNotIn(child_name, containers) # and its gone output = _lxc_ls() self.assertNotIn(child_name, output) yield master_container.destroy()
def test_container_clone(self): self.addCleanup(self.clean_container, DEFAULT_CONTAINER) self.addCleanup(self.clean_container, DEFAULT_CONTAINER + "_child") master_container = LXCContainer(DEFAULT_CONTAINER, origin="ppa", public_key="dsa...") # verify that we cannot clone an unconstructed container failure = master_container.clone("test_lxc_fail") yield self.assertFailure(failure, LXCError) yield master_container.create() # Clone a child container from the template child_name = DEFAULT_CONTAINER + "_child" c = yield master_container.clone(child_name) self.assertEqual(c.container_name, child_name) running = yield c.is_running() self.assertFalse(running) yield c.run() running = yield c.is_running() self.assertTrue(running) output = _lxc_ls() self.assertIn(DEFAULT_CONTAINER, output) self.verify_container(c, "dsa...", "ppa") # verify that we are in containers containers = yield get_containers(None) self.assertEqual(containers[child_name], True) # tear it down yield c.destroy() running = yield c.is_running() self.assertFalse(running) containers = yield get_containers(None) self.assertNotIn(child_name, containers) # and its gone output = _lxc_ls() self.assertNotIn(child_name, output) yield master_container.destroy()
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)