mirror of
https://github.com/docker/compose.git
synced 2025-07-21 04:34:38 +02:00
Update service tests to use mounts instead of volumes
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
73de81b51c
commit
3bdcc9d954
@ -88,13 +88,13 @@ class ServiceTest(DockerClientTestCase):
|
|||||||
service = self.create_service('db', volumes=[VolumeSpec.parse('/var/db')])
|
service = self.create_service('db', volumes=[VolumeSpec.parse('/var/db')])
|
||||||
container = service.create_container()
|
container = service.create_container()
|
||||||
container.start()
|
container.start()
|
||||||
self.assertIn('/var/db', container.get('Volumes'))
|
self.assertIsNotNone(container.get_mount('/var/db'))
|
||||||
|
|
||||||
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()
|
||||||
container.start()
|
container.start()
|
||||||
self.assertEqual('foodriver', container.get('Config.VolumeDriver'))
|
self.assertEqual('foodriver', container.get('HostConfig.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)
|
||||||
@ -158,12 +158,10 @@ class ServiceTest(DockerClientTestCase):
|
|||||||
volumes=[VolumeSpec(host_path, container_path, 'rw')])
|
volumes=[VolumeSpec(host_path, container_path, 'rw')])
|
||||||
container = service.create_container()
|
container = service.create_container()
|
||||||
container.start()
|
container.start()
|
||||||
|
self.assertIsNotNone(container.get_mount(container_path))
|
||||||
volumes = container.inspect()['Volumes']
|
|
||||||
self.assertIn(container_path, volumes)
|
|
||||||
|
|
||||||
# Match the last component ("host-path"), because boot2docker symlinks /tmp
|
# Match the last component ("host-path"), because boot2docker symlinks /tmp
|
||||||
actual_host_path = volumes[container_path]
|
actual_host_path = container.get_mount(container_path)['Source']
|
||||||
self.assertTrue(path.basename(actual_host_path) == path.basename(host_path),
|
self.assertTrue(path.basename(actual_host_path) == path.basename(host_path),
|
||||||
msg=("Last component differs: %s, %s" % (actual_host_path, host_path)))
|
msg=("Last component differs: %s, %s" % (actual_host_path, host_path)))
|
||||||
|
|
||||||
@ -173,10 +171,10 @@ class ServiceTest(DockerClientTestCase):
|
|||||||
"""
|
"""
|
||||||
service = self.create_service('data', volumes=[VolumeSpec.parse('/data/')])
|
service = self.create_service('data', volumes=[VolumeSpec.parse('/data/')])
|
||||||
old_container = create_and_start_container(service)
|
old_container = create_and_start_container(service)
|
||||||
volume_path = old_container.get('Volumes')['/data']
|
volume_path = old_container.get_mount('/data')['Source']
|
||||||
|
|
||||||
new_container = service.recreate_container(old_container)
|
new_container = service.recreate_container(old_container)
|
||||||
self.assertEqual(new_container.get('Volumes')['/data'], volume_path)
|
self.assertEqual(new_container.get_mount('/data')['Source'], volume_path)
|
||||||
|
|
||||||
def test_duplicate_volume_trailing_slash(self):
|
def test_duplicate_volume_trailing_slash(self):
|
||||||
"""
|
"""
|
||||||
@ -250,7 +248,7 @@ class ServiceTest(DockerClientTestCase):
|
|||||||
self.assertEqual(old_container.name, 'composetest_db_1')
|
self.assertEqual(old_container.name, 'composetest_db_1')
|
||||||
old_container.start()
|
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_mount('/etc')['Source']
|
||||||
|
|
||||||
num_containers_before = len(self.client.containers(all=True))
|
num_containers_before = len(self.client.containers(all=True))
|
||||||
|
|
||||||
@ -262,7 +260,7 @@ class ServiceTest(DockerClientTestCase):
|
|||||||
self.assertEqual(new_container.get('Config.Cmd'), ['-d', '1'])
|
self.assertEqual(new_container.get('Config.Cmd'), ['-d', '1'])
|
||||||
self.assertIn('FOO=2', new_container.get('Config.Env'))
|
self.assertIn('FOO=2', new_container.get('Config.Env'))
|
||||||
self.assertEqual(new_container.name, 'composetest_db_1')
|
self.assertEqual(new_container.name, 'composetest_db_1')
|
||||||
self.assertEqual(new_container.get('Volumes')['/etc'], volume_path)
|
self.assertEqual(new_container.get_mount('/etc')['Source'], volume_path)
|
||||||
self.assertIn(
|
self.assertIn(
|
||||||
'affinity:container==%s' % old_container.id,
|
'affinity:container==%s' % old_container.id,
|
||||||
new_container.get('Config.Env'))
|
new_container.get('Config.Env'))
|
||||||
@ -305,14 +303,18 @@ class ServiceTest(DockerClientTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
old_container = create_and_start_container(service)
|
old_container = create_and_start_container(service)
|
||||||
self.assertEqual(list(old_container.get('Volumes').keys()), ['/data'])
|
self.assertEqual(
|
||||||
volume_path = old_container.get('Volumes')['/data']
|
[mount['Destination'] for mount in old_container.get('Mounts')], ['/data']
|
||||||
|
)
|
||||||
|
volume_path = old_container.get_mount('/data')['Source']
|
||||||
|
|
||||||
new_container, = service.execute_convergence_plan(
|
new_container, = service.execute_convergence_plan(
|
||||||
ConvergencePlan('recreate', [old_container]))
|
ConvergencePlan('recreate', [old_container]))
|
||||||
|
|
||||||
self.assertEqual(list(new_container.get('Volumes')), ['/data'])
|
self.assertEqual(
|
||||||
self.assertEqual(new_container.get('Volumes')['/data'], volume_path)
|
[mount['Destination'] for mount in new_container.get('Mounts')], ['/data']
|
||||||
|
)
|
||||||
|
self.assertEqual(new_container.get_mount('/data')['Source'], volume_path)
|
||||||
|
|
||||||
def test_execute_convergence_plan_when_image_volume_masks_config(self):
|
def test_execute_convergence_plan_when_image_volume_masks_config(self):
|
||||||
service = self.create_service(
|
service = self.create_service(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user