def setUp(self): docker_client = VirtualDockerClient.with_containers() image_dict = docker_client.inspect_image( 'simphonyproject/simphony-mayavi:0.6.0') self.image_1 = Image.from_docker_dict(image_dict) image_dict = docker_client.inspect_image( 'simphonyproject/ubuntu-image:latest') self.image_2 = Image.from_docker_dict(image_dict)
def get_app(self): self.reg = registry.Registry() self.reg.register(ApplicationHandler) self.reg.authenticator = DummyAuthenticator handlers = self.reg.api_handlers('/') app = web.Application(handlers=handlers) app.db = Mock() app.hub = create_hub() app.container_manager = Mock() app.container_manager.image = mock_coro_factory( return_value=Image(name="boo", ui_name="foo_ui")) app.container_manager.find_containers = mock_coro_factory( return_value=[]) application_mock_1 = Mock() application_mock_1.image = "hello1" application_mock_2 = Mock() application_mock_2.image = "hello2" policy = Mock( allow_home=True, volume_source="foo", volume_target="bar", volume_mode="ro", ) app.db.get_accounting_for_user = Mock(return_value=[ Mock(id="one", application=application_mock_1, application_policy=policy), Mock(id="two", application=application_mock_2, application_policy=policy), ]) return app
def test_items(self): manager = self._app.container_manager manager.image = mock_coro_factory(Image()) manager.find_containers = mock_coro_factory([ DockerContainer(user="******", mapping_id="whatever", url_id="12345", name="container", image_name="image") ]) code, data = self.get("/user/johndoe/api/v1/containers/", httpstatus.OK) # We get two because we have two mapping ids, hence the find_containers # gets called once per each mapping id. # This is a kind of unusual case, because we only get one item # in the items list, due to the nature of the test. self.assertEqual( data, { 'identifiers': ['12345', '12345'], 'total': 2, 'offset': 0, 'items': { '12345': { 'image_name': 'image', 'name': 'container', 'mapping_id': 'whatever' } } })
def test_missing_image_type(self): docker_client = VirtualDockerClient.with_containers() image_dict = docker_client.inspect_image( 'simphonyproject/ubuntu-image:latest') # noqa image = Image.from_docker_dict(image_dict) self.assertEqual(image.type, '') self.assertEqual(image.env, {})
def image(self, image_id_or_name): """Returns the Image object associated to a given id """ try: image_dict = yield self._docker_client.inspect_image( image_id_or_name) except NotFound: return None return Image.from_docker_dict(image_dict)
def test_from_docker_dict_images(self): docker_client = VirtualDockerClient.with_containers() image_dict = docker_client.images()[0] image = Image.from_docker_dict(image_dict) self.assertEqual(image.docker_id, image_dict["Id"]) self.assertEqual(image.name, image_dict["RepoTags"][0]) self.assertEqual(image.description, image_dict["Labels"][SIMPHONY_NS.description]) self.assertEqual(image.ui_name, image_dict["Labels"][SIMPHONY_NS.ui_name]) self.assertEqual(image.type, 'vncapp')
def test_items_with_none_container(self): manager = self._app.container_manager manager.image = mock_coro_factory(Image()) manager.find_container = mock_coro_factory(None) code, data = self.get("/user/johndoe/api/v1/containers/", httpstatus.OK) self.assertEqual(data, { 'identifiers': [], 'total': 0, 'offset': 0, 'items': {} })
def test_from_docker_dict_inspect_image(self): docker_client = VirtualDockerClient.with_containers() image_dict = docker_client.inspect_image( 'simphonyproject/simphony-mayavi:0.6.0') # noqa labels = image_dict['Config']['Labels'] # Insert an unpalatable label for the envs. labels[SIMPHONY_NS_ENV["x11-height"] + ".whatever"] = None image = Image.from_docker_dict(image_dict) self.assertEqual(image.docker_id, image_dict["Id"]) self.assertEqual(image.name, image_dict["RepoTags"][0]) self.assertEqual( image.description, image_dict['Config']["Labels"][SIMPHONY_NS.description]) self.assertEqual(image.ui_name, image_dict['Config']["Labels"][SIMPHONY_NS.ui_name]) self.assertEqual(image.type, 'vncapp') self.assertEqual(image.env, { "X11_WIDTH": "", "X11_DEPTH": "", "X11_HEIGHT": "", })