|
@@ -30,7 +30,8 @@ from compose.service import VolumeFromSpec
|
|
|
|
|
|
def create_and_start_container(service, **override_options):
|
|
def create_and_start_container(service, **override_options):
|
|
container = service.create_container(**override_options)
|
|
container = service.create_container(**override_options)
|
|
- return service.start_container(container)
|
|
|
|
|
|
+ container.start()
|
|
|
|
+ return container
|
|
|
|
|
|
|
|
|
|
class ServiceTest(DockerClientTestCase):
|
|
class ServiceTest(DockerClientTestCase):
|
|
@@ -115,19 +116,19 @@ class ServiceTest(DockerClientTestCase):
|
|
def test_create_container_with_unspecified_volume(self):
|
|
def test_create_container_with_unspecified_volume(self):
|
|
service = self.create_service('db', volumes=['/var/db'])
|
|
service = self.create_service('db', volumes=['/var/db'])
|
|
container = service.create_container()
|
|
container = service.create_container()
|
|
- service.start_container(container)
|
|
|
|
|
|
+ container.start()
|
|
self.assertIn('/var/db', container.get('Volumes'))
|
|
self.assertIn('/var/db', container.get('Volumes'))
|
|
|
|
|
|
def test_create_container_with_volume_driver(self):
|
|
def test_create_container_with_volume_driver(self):
|
|
service = self.create_service('db', volume_driver='foodriver')
|
|
service = self.create_service('db', volume_driver='foodriver')
|
|
container = service.create_container()
|
|
container = service.create_container()
|
|
- service.start_container(container)
|
|
|
|
|
|
+ container.start()
|
|
self.assertEqual('foodriver', container.get('Config.VolumeDriver'))
|
|
self.assertEqual('foodriver', container.get('Config.VolumeDriver'))
|
|
|
|
|
|
def test_create_container_with_cpu_shares(self):
|
|
def test_create_container_with_cpu_shares(self):
|
|
service = self.create_service('db', cpu_shares=73)
|
|
service = self.create_service('db', cpu_shares=73)
|
|
container = service.create_container()
|
|
container = service.create_container()
|
|
- service.start_container(container)
|
|
|
|
|
|
+ container.start()
|
|
self.assertEqual(container.get('HostConfig.CpuShares'), 73)
|
|
self.assertEqual(container.get('HostConfig.CpuShares'), 73)
|
|
|
|
|
|
def test_build_extra_hosts(self):
|
|
def test_build_extra_hosts(self):
|
|
@@ -165,7 +166,7 @@ class ServiceTest(DockerClientTestCase):
|
|
extra_hosts = ['somehost:162.242.195.82', 'otherhost:50.31.209.229']
|
|
extra_hosts = ['somehost:162.242.195.82', 'otherhost:50.31.209.229']
|
|
service = self.create_service('db', extra_hosts=extra_hosts)
|
|
service = self.create_service('db', extra_hosts=extra_hosts)
|
|
container = service.create_container()
|
|
container = service.create_container()
|
|
- service.start_container(container)
|
|
|
|
|
|
+ container.start()
|
|
self.assertEqual(set(container.get('HostConfig.ExtraHosts')), set(extra_hosts))
|
|
self.assertEqual(set(container.get('HostConfig.ExtraHosts')), set(extra_hosts))
|
|
|
|
|
|
def test_create_container_with_extra_hosts_dicts(self):
|
|
def test_create_container_with_extra_hosts_dicts(self):
|
|
@@ -173,33 +174,33 @@ class ServiceTest(DockerClientTestCase):
|
|
extra_hosts_list = ['somehost:162.242.195.82', 'otherhost:50.31.209.229']
|
|
extra_hosts_list = ['somehost:162.242.195.82', 'otherhost:50.31.209.229']
|
|
service = self.create_service('db', extra_hosts=extra_hosts)
|
|
service = self.create_service('db', extra_hosts=extra_hosts)
|
|
container = service.create_container()
|
|
container = service.create_container()
|
|
- service.start_container(container)
|
|
|
|
|
|
+ container.start()
|
|
self.assertEqual(set(container.get('HostConfig.ExtraHosts')), set(extra_hosts_list))
|
|
self.assertEqual(set(container.get('HostConfig.ExtraHosts')), set(extra_hosts_list))
|
|
|
|
|
|
def test_create_container_with_cpu_set(self):
|
|
def test_create_container_with_cpu_set(self):
|
|
service = self.create_service('db', cpuset='0')
|
|
service = self.create_service('db', cpuset='0')
|
|
container = service.create_container()
|
|
container = service.create_container()
|
|
- service.start_container(container)
|
|
|
|
|
|
+ container.start()
|
|
self.assertEqual(container.get('HostConfig.CpusetCpus'), '0')
|
|
self.assertEqual(container.get('HostConfig.CpusetCpus'), '0')
|
|
|
|
|
|
def test_create_container_with_read_only_root_fs(self):
|
|
def test_create_container_with_read_only_root_fs(self):
|
|
read_only = True
|
|
read_only = True
|
|
service = self.create_service('db', read_only=read_only)
|
|
service = self.create_service('db', read_only=read_only)
|
|
container = service.create_container()
|
|
container = service.create_container()
|
|
- service.start_container(container)
|
|
|
|
|
|
+ container.start()
|
|
self.assertEqual(container.get('HostConfig.ReadonlyRootfs'), read_only, container.get('HostConfig'))
|
|
self.assertEqual(container.get('HostConfig.ReadonlyRootfs'), read_only, container.get('HostConfig'))
|
|
|
|
|
|
def test_create_container_with_security_opt(self):
|
|
def test_create_container_with_security_opt(self):
|
|
security_opt = ['label:disable']
|
|
security_opt = ['label:disable']
|
|
service = self.create_service('db', security_opt=security_opt)
|
|
service = self.create_service('db', security_opt=security_opt)
|
|
container = service.create_container()
|
|
container = service.create_container()
|
|
- service.start_container(container)
|
|
|
|
|
|
+ container.start()
|
|
self.assertEqual(set(container.get('HostConfig.SecurityOpt')), set(security_opt))
|
|
self.assertEqual(set(container.get('HostConfig.SecurityOpt')), set(security_opt))
|
|
|
|
|
|
def test_create_container_with_mac_address(self):
|
|
def test_create_container_with_mac_address(self):
|
|
service = self.create_service('db', mac_address='02:42:ac:11:65:43')
|
|
service = self.create_service('db', mac_address='02:42:ac:11:65:43')
|
|
container = service.create_container()
|
|
container = service.create_container()
|
|
- service.start_container(container)
|
|
|
|
|
|
+ container.start()
|
|
self.assertEqual(container.inspect()['Config']['MacAddress'], '02:42:ac:11:65:43')
|
|
self.assertEqual(container.inspect()['Config']['MacAddress'], '02:42:ac:11:65:43')
|
|
|
|
|
|
def test_create_container_with_specified_volume(self):
|
|
def test_create_container_with_specified_volume(self):
|
|
@@ -208,7 +209,7 @@ class ServiceTest(DockerClientTestCase):
|
|
|
|
|
|
service = self.create_service('db', volumes=['%s:%s' % (host_path, container_path)])
|
|
service = self.create_service('db', volumes=['%s:%s' % (host_path, container_path)])
|
|
container = service.create_container()
|
|
container = service.create_container()
|
|
- service.start_container(container)
|
|
|
|
|
|
+ container.start()
|
|
|
|
|
|
volumes = container.inspect()['Volumes']
|
|
volumes = container.inspect()['Volumes']
|
|
self.assertIn(container_path, volumes)
|
|
self.assertIn(container_path, volumes)
|
|
@@ -281,7 +282,7 @@ class ServiceTest(DockerClientTestCase):
|
|
]
|
|
]
|
|
)
|
|
)
|
|
host_container = host_service.create_container()
|
|
host_container = host_service.create_container()
|
|
- host_service.start_container(host_container)
|
|
|
|
|
|
+ host_container.start()
|
|
self.assertIn(volume_container_1.id + ':rw',
|
|
self.assertIn(volume_container_1.id + ':rw',
|
|
host_container.get('HostConfig.VolumesFrom'))
|
|
host_container.get('HostConfig.VolumesFrom'))
|
|
self.assertIn(volume_container_2.id + ':rw',
|
|
self.assertIn(volume_container_2.id + ':rw',
|
|
@@ -300,7 +301,7 @@ class ServiceTest(DockerClientTestCase):
|
|
self.assertEqual(old_container.get('Config.Cmd'), ['-d', '1'])
|
|
self.assertEqual(old_container.get('Config.Cmd'), ['-d', '1'])
|
|
self.assertIn('FOO=1', old_container.get('Config.Env'))
|
|
self.assertIn('FOO=1', old_container.get('Config.Env'))
|
|
self.assertEqual(old_container.name, 'composetest_db_1')
|
|
self.assertEqual(old_container.name, 'composetest_db_1')
|
|
- service.start_container(old_container)
|
|
|
|
|
|
+ old_container.start()
|
|
old_container.inspect() # reload volume data
|
|
old_container.inspect() # reload volume data
|
|
volume_path = old_container.get('Volumes')['/etc']
|
|
volume_path = old_container.get('Volumes')['/etc']
|
|
|
|
|