mirror of https://github.com/docker/compose.git
Remove unused intermediate_container from return value.
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
This commit is contained in:
parent
4827e60641
commit
26f45efea2
|
@ -176,18 +176,14 @@ class Project(object):
|
|||
do_build=True):
|
||||
running_containers = []
|
||||
for service in self.get_services(service_names, include_links=start_links):
|
||||
if recreate:
|
||||
for (_, container) in service.recreate_containers(
|
||||
insecure_registry=insecure_registry,
|
||||
create_func = (service.recreate_containers if recreate
|
||||
else service.start_or_create_containers)
|
||||
|
||||
for container in create_func(
|
||||
insecure_registry=insecure_registry,
|
||||
detach=detach,
|
||||
do_build=do_build):
|
||||
running_containers.append(container)
|
||||
else:
|
||||
for container in service.start_or_create_containers(
|
||||
insecure_registry=insecure_registry,
|
||||
detach=detach,
|
||||
do_build=do_build):
|
||||
running_containers.append(container)
|
||||
running_containers.append(container)
|
||||
|
||||
return running_containers
|
||||
|
||||
|
|
|
@ -242,8 +242,9 @@ class Service(object):
|
|||
|
||||
def recreate_containers(self, insecure_registry=False, do_build=True, **override_options):
|
||||
"""
|
||||
If a container for this service doesn't exist, create and start one. If there are
|
||||
any, stop them, create+start new ones, and remove the old containers.
|
||||
If a container for this service doesn't exist, create and start one. If
|
||||
there are any, stop them, create+start new ones, and remove the old
|
||||
containers.
|
||||
"""
|
||||
containers = self.containers(stopped=True)
|
||||
if not containers:
|
||||
|
@ -253,21 +254,22 @@ class Service(object):
|
|||
do_build=do_build,
|
||||
**override_options)
|
||||
self.start_container(container)
|
||||
return [(None, container)]
|
||||
return [container]
|
||||
else:
|
||||
tuples = []
|
||||
|
||||
for c in containers:
|
||||
log.info("Recreating %s..." % c.name)
|
||||
tuples.append(self.recreate_container(c, insecure_registry=insecure_registry, **override_options))
|
||||
|
||||
return tuples
|
||||
return [
|
||||
self.recreate_container(
|
||||
container,
|
||||
insecure_registry=insecure_registry,
|
||||
**override_options)
|
||||
for container in containers
|
||||
]
|
||||
|
||||
def recreate_container(self, container, **override_options):
|
||||
"""Recreate a container. An intermediate container is created so that
|
||||
the new container has the same name, while still supporting
|
||||
`volumes-from` the original container.
|
||||
"""
|
||||
log.info("Recreating %s..." % container.name)
|
||||
try:
|
||||
container.stop()
|
||||
except APIError as e:
|
||||
|
@ -295,7 +297,7 @@ class Service(object):
|
|||
|
||||
intermediate_container.remove()
|
||||
|
||||
return (intermediate_container, new_container)
|
||||
return new_container
|
||||
|
||||
def start_container_if_stopped(self, container, **options):
|
||||
if container.is_running:
|
||||
|
|
|
@ -148,30 +148,23 @@ class ServiceTest(DockerClientTestCase):
|
|||
self.assertIn('FOO=1', old_container.dictionary['Config']['Env'])
|
||||
self.assertEqual(old_container.name, 'figtest_db_1')
|
||||
service.start_container(old_container)
|
||||
volume_path = old_container.inspect()['Volumes']['/etc']
|
||||
volume_path = old_container.get('Volumes')['/etc']
|
||||
|
||||
num_containers_before = len(self.client.containers(all=True))
|
||||
|
||||
service.options['environment']['FOO'] = '2'
|
||||
tuples = service.recreate_containers()
|
||||
self.assertEqual(len(tuples), 1)
|
||||
containers = service.recreate_containers()
|
||||
self.assertEqual(len(containers), 1)
|
||||
|
||||
intermediate_container = tuples[0][0]
|
||||
new_container = tuples[0][1]
|
||||
self.assertEqual(intermediate_container.dictionary['Config']['Entrypoint'], ['/bin/echo'])
|
||||
|
||||
self.assertEqual(new_container.dictionary['Config']['Entrypoint'], ['sleep'])
|
||||
self.assertEqual(new_container.dictionary['Config']['Cmd'], ['300'])
|
||||
self.assertIn('FOO=2', new_container.dictionary['Config']['Env'])
|
||||
new_container = containers[0]
|
||||
self.assertEqual(new_container.get('Config.Entrypoint'), ['sleep'])
|
||||
self.assertEqual(new_container.get('Config.Cmd'), ['300'])
|
||||
self.assertIn('FOO=2', new_container.get('Config.Env'))
|
||||
self.assertEqual(new_container.name, 'figtest_db_1')
|
||||
self.assertEqual(new_container.inspect()['Volumes']['/etc'], volume_path)
|
||||
self.assertIn(intermediate_container.id, new_container.dictionary['HostConfig']['VolumesFrom'])
|
||||
self.assertEqual(new_container.get('Volumes')['/etc'], volume_path)
|
||||
|
||||
self.assertEqual(len(self.client.containers(all=True)), num_containers_before)
|
||||
self.assertNotEqual(old_container.id, new_container.id)
|
||||
self.assertRaises(APIError,
|
||||
self.client.inspect_container,
|
||||
intermediate_container.id)
|
||||
|
||||
def test_recreate_containers_when_containers_are_stopped(self):
|
||||
service = self.create_service(
|
||||
|
|
Loading…
Reference in New Issue