mirror of https://github.com/docker/compose.git
Fix lookup of linked containers for API version 1.20
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
97fe2ee40c
commit
4bf2f8c4f9
|
@ -228,16 +228,6 @@ class Container(object):
|
|||
self.has_been_inspected = True
|
||||
return self.dictionary
|
||||
|
||||
# TODO: only used by tests, move to test module
|
||||
def links(self):
|
||||
links = []
|
||||
for container in self.client.containers():
|
||||
for name in container['Names']:
|
||||
bits = name.split('/')
|
||||
if len(bits) > 2 and bits[1] == self.name:
|
||||
links.append(bits[2])
|
||||
return links
|
||||
|
||||
def attach(self, *args, **kwargs):
|
||||
return self.client.attach(self.id, *args, **kwargs)
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ from compose.cli.command import get_project
|
|||
from compose.cli.docker_client import docker_client
|
||||
from compose.container import Container
|
||||
from tests.integration.testcases import DockerClientTestCase
|
||||
from tests.integration.testcases import get_links
|
||||
from tests.integration.testcases import pull_busybox
|
||||
|
||||
|
||||
|
@ -909,7 +910,7 @@ class CLITestCase(DockerClientTestCase):
|
|||
|
||||
web, other, db = containers
|
||||
self.assertEqual(web.human_readable_command, 'top')
|
||||
self.assertTrue({'db', 'other'} <= set(web.links()))
|
||||
self.assertTrue({'db', 'other'} <= set(get_links(web)))
|
||||
self.assertEqual(db.human_readable_command, 'top')
|
||||
self.assertEqual(other.human_readable_command, 'top')
|
||||
|
||||
|
@ -931,7 +932,9 @@ class CLITestCase(DockerClientTestCase):
|
|||
self.assertEqual(len(containers), 2)
|
||||
web = containers[1]
|
||||
|
||||
self.assertEqual(set(web.links()), set(['db', 'mydb_1', 'extends_mydb_1']))
|
||||
self.assertEqual(
|
||||
set(get_links(web)),
|
||||
set(['db', 'mydb_1', 'extends_mydb_1']))
|
||||
|
||||
expected_env = set([
|
||||
"FOO=1",
|
||||
|
|
|
@ -340,7 +340,6 @@ class ProjectTest(DockerClientTestCase):
|
|||
|
||||
db_container = [c for c in project.containers() if 'db' in c.name][0]
|
||||
self.assertEqual(db_container.id, old_db_id)
|
||||
mount, = db_container.get('Mounts')
|
||||
self.assertEqual(
|
||||
db_container.get_mount('/var/db')['Source'],
|
||||
db_volume_path)
|
||||
|
|
|
@ -12,6 +12,7 @@ from six import text_type
|
|||
|
||||
from .. import mock
|
||||
from .testcases import DockerClientTestCase
|
||||
from .testcases import get_links
|
||||
from .testcases import pull_busybox
|
||||
from compose import __version__
|
||||
from compose.config.types import VolumeFromSpec
|
||||
|
@ -88,7 +89,7 @@ class ServiceTest(DockerClientTestCase):
|
|||
service = self.create_service('db', volumes=[VolumeSpec.parse('/var/db')])
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
self.assertIsNotNone(container.get_mount('/var/db'))
|
||||
assert container.get_mount('/var/db')
|
||||
|
||||
def test_create_container_with_volume_driver(self):
|
||||
service = self.create_service('db', volume_driver='foodriver')
|
||||
|
@ -158,7 +159,7 @@ class ServiceTest(DockerClientTestCase):
|
|||
volumes=[VolumeSpec(host_path, container_path, 'rw')])
|
||||
container = service.create_container()
|
||||
container.start()
|
||||
self.assertIsNotNone(container.get_mount(container_path))
|
||||
assert container.get_mount(container_path)
|
||||
|
||||
# Match the last component ("host-path"), because boot2docker symlinks /tmp
|
||||
actual_host_path = container.get_mount(container_path)['Source']
|
||||
|
@ -385,7 +386,7 @@ class ServiceTest(DockerClientTestCase):
|
|||
create_and_start_container(web)
|
||||
|
||||
self.assertEqual(
|
||||
set(web.containers()[0].links()),
|
||||
set(get_links(web.containers()[0])),
|
||||
set([
|
||||
'composetest_db_1', 'db_1',
|
||||
'composetest_db_2', 'db_2',
|
||||
|
@ -401,7 +402,7 @@ class ServiceTest(DockerClientTestCase):
|
|||
create_and_start_container(web)
|
||||
|
||||
self.assertEqual(
|
||||
set(web.containers()[0].links()),
|
||||
set(get_links(web.containers()[0])),
|
||||
set([
|
||||
'composetest_db_1', 'db_1',
|
||||
'composetest_db_2', 'db_2',
|
||||
|
@ -419,7 +420,7 @@ class ServiceTest(DockerClientTestCase):
|
|||
create_and_start_container(web)
|
||||
|
||||
self.assertEqual(
|
||||
set(web.containers()[0].links()),
|
||||
set(get_links(web.containers()[0])),
|
||||
set([
|
||||
'composetest_db_1',
|
||||
'composetest_db_2',
|
||||
|
@ -433,7 +434,7 @@ class ServiceTest(DockerClientTestCase):
|
|||
create_and_start_container(db)
|
||||
|
||||
c = create_and_start_container(db)
|
||||
self.assertEqual(set(c.links()), set([]))
|
||||
self.assertEqual(set(get_links(c)), set([]))
|
||||
|
||||
def test_start_one_off_container_creates_links_to_its_own_service(self):
|
||||
db = self.create_service('db')
|
||||
|
@ -444,7 +445,7 @@ class ServiceTest(DockerClientTestCase):
|
|||
c = create_and_start_container(db, one_off=True)
|
||||
|
||||
self.assertEqual(
|
||||
set(c.links()),
|
||||
set(get_links(c)),
|
||||
set([
|
||||
'composetest_db_1', 'db_1',
|
||||
'composetest_db_2', 'db_2',
|
||||
|
|
|
@ -7,6 +7,7 @@ from __future__ import unicode_literals
|
|||
import py
|
||||
|
||||
from .testcases import DockerClientTestCase
|
||||
from .testcases import get_links
|
||||
from compose.config import config
|
||||
from compose.project import Project
|
||||
from compose.service import ConvergenceStrategy
|
||||
|
@ -186,8 +187,8 @@ class ProjectWithDependenciesTest(ProjectTestCase):
|
|||
web, = [c for c in containers if c.service == 'web']
|
||||
nginx, = [c for c in containers if c.service == 'nginx']
|
||||
|
||||
self.assertEqual(web.links(), ['composetest_db_1', 'db', 'db_1'])
|
||||
self.assertEqual(nginx.links(), ['composetest_web_1', 'web', 'web_1'])
|
||||
self.assertEqual(set(get_links(web)), {'composetest_db_1', 'db', 'db_1'})
|
||||
self.assertEqual(set(get_links(nginx)), {'composetest_web_1', 'web', 'web_1'})
|
||||
|
||||
|
||||
class ServiceStateTest(DockerClientTestCase):
|
||||
|
|
|
@ -16,6 +16,16 @@ def pull_busybox(client):
|
|||
client.pull('busybox:latest', stream=False)
|
||||
|
||||
|
||||
def get_links(container):
|
||||
links = container.get('HostConfig.Links') or []
|
||||
|
||||
def format_link(link):
|
||||
_, alias = link.split(':')
|
||||
return alias.split('/')[-1]
|
||||
|
||||
return [format_link(link) for link in links]
|
||||
|
||||
|
||||
class DockerClientTestCase(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
|
Loading…
Reference in New Issue