def test_start_container(self): docker.create_container(self._container) self.assertIsNotNone(docker.inspect_container(self._container)) docker.start_container(self._container) stat = docker.inspect_container(self._container) self.assertIsNotNone(stat) self.assertTrue(stat['State']['Running'])
def test_create_container(self): docker.create_container(self._container, force=False) self.assertIsNotNone(docker.inspect_container(self._container)) self.assertRaises( Exception, lambda: docker.create_container(self._container, force=False)) self.assertIsNotNone(docker.inspect_container(self._container))
def test_container_exec_error(self): docker.create_container(self._container) self.assertIsNotNone(docker.inspect_container(self._container)) self.assertRaises( Exception, lambda: docker.exec_cmd(self._container, 'echo hello!')) docker.delete_container(self._container) self.assertIsNone(docker.inspect_container(self._container)) self.assertRaises( Exception, lambda: docker.exec_cmd(self._container, 'echo hello!'))
def test_image(self): file = 'data/examples/nc-server/nc-image.yaml' up_plan = self.o.read_plan_file( 'data/examples/nc-server/nc-image.up.plan') down_plan = self.o.read_plan_file( 'data/examples/nc-server/nc-image.down.plan') tpl = self.get_tpl(file) temp_stdout = StringIO() with self.redirect_stdout(temp_stdout): self.assertTrue(self.o.orchestrate(file, up_plan)) self.assert_create(tpl) self.assert_start(tpl) con_id = docker.inspect_container('tosker_nc-image.server')['Id'] output = temp_stdout.getvalue().strip() self.assertIn('- container_id: {}'.format(con_id), output) self.assertIn('- env_variable: hello_world', output) with self.redirect_stdout(StringIO()): self.assertTrue(self.o.orchestrate(file, down_plan)) self.assert_delete(tpl)
def assert_delete(self, tpl): for c in tpl.containers: self.assertIsNone(docker.inspect_container(c)) for c in tpl.volumes: self.assertIsNone(docker.inspect_volume(c))
def _assert_start(self, tpl, check): for c in tpl.containers: stat = docker.inspect_container(c) self.assertIsNotNone(stat) self.assertTrue(check(stat))
def test_container_exec(self): docker.create_container(self._container) self.assertIsNotNone(docker.inspect_container(self._container)) docker.start_container(self._container) docker.exec_cmd(self._container, 'echo hello!')
def test_container_delete_error(self): self.assertRaises(Exception, lambda: docker.delete_container(self._container)) self.assertIsNone(docker.inspect_container(self._container))
def test_container_delete(self): docker.create_container(self._container) self.assertIsNotNone(docker.inspect_container(self._container)) docker.delete_container(self._container) self.assertIsNone(docker.inspect_container(self._container))