Connect services to networks with the 'networks' key
Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
parent
3f9038aea9
commit
3eafdbb01b
12 changed files with 195 additions and 78 deletions
|
|
@ -17,7 +17,7 @@ class ResilienceTest(DockerClientTestCase):
|
|||
self.project = Project('composetest', [self.db], self.client)
|
||||
|
||||
container = self.db.create_container()
|
||||
container.start()
|
||||
self.db.start_container(container)
|
||||
self.host_path = container.get_mount('/var/db')['Source']
|
||||
|
||||
def test_successful_recreate(self):
|
||||
|
|
@ -35,7 +35,7 @@ class ResilienceTest(DockerClientTestCase):
|
|||
self.assertEqual(container.get_mount('/var/db')['Source'], self.host_path)
|
||||
|
||||
def test_start_failure(self):
|
||||
with mock.patch('compose.container.Container.start', crash):
|
||||
with mock.patch('compose.service.Service.start_container', crash):
|
||||
with self.assertRaises(Crash):
|
||||
self.project.up(strategy=ConvergenceStrategy.always)
|
||||
|
||||
|
|
|
|||
|
|
@ -32,14 +32,7 @@ from compose.service import Service
|
|||
|
||||
def create_and_start_container(service, **override_options):
|
||||
container = service.create_container(**override_options)
|
||||
container.start()
|
||||
return container
|
||||
|
||||
|
||||
def remove_stopped(service):
|
||||
containers = [c for c in service.containers(stopped=True) if not c.is_running]
|
||||
for container in containers:
|
||||
container.remove()
|
||||
return service.start_container(container)
|
||||
|
||||
|
||||
class ServiceTest(DockerClientTestCase):
|
||||
|
|
@ -88,19 +81,19 @@ class ServiceTest(DockerClientTestCase):
|
|||
def test_create_container_with_unspecified_volume(self):
|
||||
service = self.create_service('db', volumes=[VolumeSpec.parse('/var/db')])
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
service.start_container(container)
|
||||
assert container.get_mount('/var/db')
|
||||
|
||||
def test_create_container_with_volume_driver(self):
|
||||
service = self.create_service('db', volume_driver='foodriver')
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
service.start_container(container)
|
||||
self.assertEqual('foodriver', container.get('HostConfig.VolumeDriver'))
|
||||
|
||||
def test_create_container_with_cpu_shares(self):
|
||||
service = self.create_service('db', cpu_shares=73)
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
service.start_container(container)
|
||||
self.assertEqual(container.get('HostConfig.CpuShares'), 73)
|
||||
|
||||
def test_create_container_with_cpu_quota(self):
|
||||
|
|
@ -113,7 +106,7 @@ class ServiceTest(DockerClientTestCase):
|
|||
extra_hosts = ['somehost:162.242.195.82', 'otherhost:50.31.209.229']
|
||||
service = self.create_service('db', extra_hosts=extra_hosts)
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
service.start_container(container)
|
||||
self.assertEqual(set(container.get('HostConfig.ExtraHosts')), set(extra_hosts))
|
||||
|
||||
def test_create_container_with_extra_hosts_dicts(self):
|
||||
|
|
@ -121,33 +114,33 @@ class ServiceTest(DockerClientTestCase):
|
|||
extra_hosts_list = ['somehost:162.242.195.82', 'otherhost:50.31.209.229']
|
||||
service = self.create_service('db', extra_hosts=extra_hosts)
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
service.start_container(container)
|
||||
self.assertEqual(set(container.get('HostConfig.ExtraHosts')), set(extra_hosts_list))
|
||||
|
||||
def test_create_container_with_cpu_set(self):
|
||||
service = self.create_service('db', cpuset='0')
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
service.start_container(container)
|
||||
self.assertEqual(container.get('HostConfig.CpusetCpus'), '0')
|
||||
|
||||
def test_create_container_with_read_only_root_fs(self):
|
||||
read_only = True
|
||||
service = self.create_service('db', read_only=read_only)
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
service.start_container(container)
|
||||
self.assertEqual(container.get('HostConfig.ReadonlyRootfs'), read_only, container.get('HostConfig'))
|
||||
|
||||
def test_create_container_with_security_opt(self):
|
||||
security_opt = ['label:disable']
|
||||
service = self.create_service('db', security_opt=security_opt)
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
service.start_container(container)
|
||||
self.assertEqual(set(container.get('HostConfig.SecurityOpt')), set(security_opt))
|
||||
|
||||
def test_create_container_with_mac_address(self):
|
||||
service = self.create_service('db', mac_address='02:42:ac:11:65:43')
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
service.start_container(container)
|
||||
self.assertEqual(container.inspect()['Config']['MacAddress'], '02:42:ac:11:65:43')
|
||||
|
||||
def test_create_container_with_specified_volume(self):
|
||||
|
|
@ -158,7 +151,7 @@ class ServiceTest(DockerClientTestCase):
|
|||
'db',
|
||||
volumes=[VolumeSpec(host_path, container_path, 'rw')])
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
service.start_container(container)
|
||||
assert container.get_mount(container_path)
|
||||
|
||||
# Match the last component ("host-path"), because boot2docker symlinks /tmp
|
||||
|
|
@ -229,7 +222,7 @@ class ServiceTest(DockerClientTestCase):
|
|||
]
|
||||
)
|
||||
host_container = host_service.create_container()
|
||||
host_container.start()
|
||||
host_service.start_container(host_container)
|
||||
self.assertIn(volume_container_1.id + ':rw',
|
||||
host_container.get('HostConfig.VolumesFrom'))
|
||||
self.assertIn(volume_container_2.id + ':rw',
|
||||
|
|
@ -248,7 +241,7 @@ class ServiceTest(DockerClientTestCase):
|
|||
self.assertEqual(old_container.get('Config.Cmd'), ['-d', '1'])
|
||||
self.assertIn('FOO=1', old_container.get('Config.Env'))
|
||||
self.assertEqual(old_container.name, 'composetest_db_1')
|
||||
old_container.start()
|
||||
service.start_container(old_container)
|
||||
old_container.inspect() # reload volume data
|
||||
volume_path = old_container.get_mount('/etc')['Source']
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue