def test_duplicate_containers(self): service = self.create_service('web') options = service._get_container_create_options({}, 1) original = Container.create(service.client, **options) self.assertEqual(set(service.containers(stopped=True)), set([original])) self.assertEqual(set(service.duplicate_containers()), set()) options['name'] = 'temporary_container_name' duplicate = Container.create(service.client, **options) self.assertEqual(set(service.containers(stopped=True)), set([original, duplicate])) self.assertEqual(set(service.duplicate_containers()), set([duplicate]))
def test_net_from_container_v1(self): def get_project(): return Project.from_config( name='composetest', config_data=build_config({ 'web': { 'image': 'busybox:latest', 'net': 'container:composetest_net_container' }, }), client=self.client, ) with pytest.raises(ConfigurationError) as excinfo: get_project() assert "container 'composetest_net_container' which does not exist" in excinfo.exconly() net_container = Container.create( self.client, image='busybox:latest', name='composetest_net_container', command='top', labels={LABEL_PROJECT: 'composetest'}, ) net_container.start() project = get_project() project.up() web = project.get_service('web') self.assertEqual(web.network_mode.mode, 'container:' + net_container.id)
def test_net_from_container(self): net_container = Container.create( self.client, image='busybox:latest', name='composetest_net_container', command='top', labels={LABEL_PROJECT: 'composetest'}, ) net_container.start() project = Project.from_dicts( name='composetest', service_dicts=build_service_dicts({ 'web': { 'image': 'busybox:latest', 'net': 'container:composetest_net_container' }, }), client=self.client, ) project.up() web = project.get_service('web') self.assertEqual(web.net.mode, 'container:' + net_container.id)
def test_net_from_container(self): net_container = Container.create( self.client, image='busybox:latest', name='composetest_net_container', command='top', labels={LABEL_PROJECT: 'composetest'}, ) net_container.start() project = Project.from_dicts( name='composetest', service_dicts=build_service_dicts({ 'web': { 'image': 'busybox:latest', 'net': 'container:composetest_net_container' }, }), client=self.client, ) project.up() web = project.get_service('web') self.assertEqual(web.net.mode, 'container:' + net_container.id)
def test_net_from_container(self): net_container = Container.create( self.client, image='busybox:latest', name='composetest_net_container', command='top' ) net_container.start() project = Project.from_dicts( name='composetest', service_dicts=config.from_dictionary({ 'web': { 'image': 'busybox:latest', 'net': 'container:composetest_net_container' }, }), client=self.client, ) project.up() web = project.get_service('web') self.assertEqual(web._get_net(), 'container:' + net_container.id) project.kill() project.remove_stopped()
def test_create_container_with_volumes_from(self): volume_service = self.create_service('data') volume_container_1 = volume_service.create_container() volume_container_2 = Container.create(self.client, image='busybox:latest', command=["/bin/sleep", "300"]) host_service = self.create_service('host', volumes_from=[volume_service, volume_container_2]) host_container = host_service.create_container() host_service.start_container(host_container) self.assertIn(volume_container_1.id, host_container.get('HostConfig.VolumesFrom')) self.assertIn(volume_container_2.id, host_container.get('HostConfig.VolumesFrom'))
def test_create_container_with_volumes_from(self): volume_service = self.create_service('data') volume_container_1 = volume_service.create_container() volume_container_2 = Container.create(self.client, image='busybox:latest', command=["/bin/sleep", "300"]) host_service = self.create_service('host', volumes_from=[volume_service, volume_container_2]) host_container = host_service.create_container() host_service.start_container(host_container) self.assertIn(volume_container_1.id, host_container.get('HostConfig.VolumesFrom')) self.assertIn(volume_container_2.id, host_container.get('HostConfig.VolumesFrom'))
def test_create_container_with_volumes_from(self): volume_service = self.create_service("data") volume_container_1 = volume_service.create_container() volume_container_2 = Container.create( self.client, image="busybox:latest", command=["top"], labels={LABEL_PROJECT: "composetest"} ) host_service = self.create_service("host", volumes_from=[volume_service, volume_container_2]) host_container = host_service.create_container() host_service.start_container(host_container) self.assertIn(volume_container_1.id, host_container.get("HostConfig.VolumesFrom")) self.assertIn(volume_container_2.id, host_container.get("HostConfig.VolumesFrom"))
def test_create_container_with_volumes_from(self): volume_service = self.create_service('data') volume_container_1 = volume_service.create_container() volume_container_2 = Container.create( self.client, image='busybox:latest', command=["top"], labels={LABEL_PROJECT: 'composetest'}, ) host_service = self.create_service('host', volumes_from=[volume_service, volume_container_2]) host_container = host_service.create_container() host_service.start_container(host_container) self.assertIn(volume_container_1.id, host_container.get('HostConfig.VolumesFrom')) self.assertIn(volume_container_2.id, host_container.get('HostConfig.VolumesFrom'))
def test_volumes_from_container(self): data_container = Container.create( self.client, image="busybox:latest", volumes=["/var/data"], name="composetest_data_container", labels={LABEL_PROJECT: "composetest"}, ) project = Project.from_dicts( name="composetest", service_dicts=build_service_dicts( {"db": {"image": "busybox:latest", "volumes_from": ["composetest_data_container"]}} ), client=self.client, ) db = project.get_service("db") self.assertEqual(db.volumes_from, [data_container])
def test_volumes_from_container(self): data_container = Container.create( self.client, image='busybox:latest', volumes=['/var/data'], name='composetest_data_container', ) project = Project.from_config( name='composetest', config={ 'db': { 'image': 'busybox:latest', 'volumes_from': ['composetest_data_container'], }, }, client=self.client, ) db = project.get_service('db') self.assertEqual(db.volumes_from, [data_container])
def test_volumes_from_container(self): data_container = Container.create( self.client, image='busybox:latest', volumes=['/var/data'], name='composetest_data_container', labels={LABEL_PROJECT: 'composetest'}, ) project = Project.from_config( name='composetest', config_data=build_config({ 'db': { 'image': 'busybox:latest', 'volumes_from': ['composetest_data_container'], }, }), client=self.client, ) db = project.get_service('db') self.assertEqual(db._get_volumes_from(), [data_container.id + ':rw'])
def test_volumes_from_container(self): data_container = Container.create( self.client, image='busybox:latest', volumes=['/var/data'], name='composetest_data_container', labels={LABEL_PROJECT: 'composetest'}, ) project = Project.from_dicts( name='composetest', service_dicts=config.from_dictionary({ 'db': { 'image': 'busybox:latest', 'volumes_from': ['composetest_data_container'], }, }), client=self.client, ) db = project.get_service('db') self.assertEqual(db.volumes_from, [data_container])
def test_net_from_container(self): net_container = Container.create( self.client, image="busybox:latest", name="composetest_net_container", command="top", labels={LABEL_PROJECT: "composetest"}, ) net_container.start() project = Project.from_dicts( name="composetest", service_dicts=build_service_dicts( {"web": {"image": "busybox:latest", "net": "container:composetest_net_container"}} ), client=self.client, ) project.up() web = project.get_service("web") self.assertEqual(web.net.mode, "container:" + net_container.id)