Use an anonymous intermediate container so that when recreating containers, suffixes always start from 1

This commit is contained in:
Aanand Prasad 2014-01-15 17:06:16 +00:00
parent 3956d85a8c
commit ea4753c49a
2 changed files with 20 additions and 5 deletions

View File

@ -97,10 +97,21 @@ class Service(object):
if container.is_running:
container.stop(timeout=1)
options = dict(override_options)
options['volumes_from'] = container.id
intermediate_container = Container.create(
self.client,
image='ubuntu',
command='echo',
volumes_from=container.id,
)
intermediate_container.start()
intermediate_container.wait()
container.remove()
return (container, self.create_container(**options))
options = dict(override_options)
options['volumes_from'] = intermediate_container.id
new_container = self.create_container(**options)
return (intermediate_container, new_container)
def start_container(self, container=None, **override_options):
if container is None:

View File

@ -112,20 +112,24 @@ class ServiceTest(DockerClientTestCase):
service = self.create_service('db', environment={'FOO': '1'}, volumes=['/var/db'])
old_container = service.create_container()
self.assertEqual(old_container.dictionary['Config']['Env'], ['FOO=1'])
self.assertEqual(old_container.name, 'figtest_db_1')
service.start_container(old_container)
volume_path = old_container.inspect()['Volumes']['/var/db']
num_containers_before = len(self.client.containers(all=True))
service.options['environment']['FOO'] = '2'
(old, new) = service.recreate_containers()
self.assertEqual(old, [old_container])
self.assertEqual(len(old), 1)
self.assertEqual(len(new), 1)
new_container = new[0]
self.assertEqual(new_container.dictionary['Config']['Env'], ['FOO=2'])
self.assertEqual(new_container.name, 'figtest_db_1')
service.start_container(new_container)
self.assertEqual(new_container.inspect()['Volumes']['/var/db'], volume_path)
self.assertEqual(len(service.containers(stopped=True)), 2)
self.assertEqual(len(self.client.containers(all=True)), num_containers_before + 1)
self.assertNotEqual(old_container.id, new_container.id)
def test_start_container_passes_through_options(self):