Fix "name is reserved" with Engine 1.10 RC1

Ensure link aliases are unique (this deduping was previously performed
on the server).

Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
Aanand Prasad 2016-01-19 11:27:27 +00:00
parent 7442b416e8
commit bb377d3fe6
2 changed files with 16 additions and 13 deletions

View File

@ -502,24 +502,31 @@ class Service(object):
if self.use_networking: if self.use_networking:
return [] return []
links = [] links = {}
for service, link_name in self.links: for service, link_name in self.links:
for container in service.containers(): for container in service.containers():
links.append((container.name, link_name or service.name)) links[link_name or service.name] = container.name
links.append((container.name, container.name)) links[container.name] = container.name
links.append((container.name, container.name_without_project)) links[container.name_without_project] = container.name
if link_to_self: if link_to_self:
for container in self.containers(): for container in self.containers():
links.append((container.name, self.name)) links[self.name] = container.name
links.append((container.name, container.name)) links[container.name] = container.name
links.append((container.name, container.name_without_project)) links[container.name_without_project] = container.name
for external_link in self.options.get('external_links') or []: for external_link in self.options.get('external_links') or []:
if ':' not in external_link: if ':' not in external_link:
link_name = external_link link_name = external_link
else: else:
external_link, link_name = external_link.split(':') external_link, link_name = external_link.split(':')
links.append((external_link, link_name)) links[link_name] = external_link
return links
return [
(alias, container_name)
for (container_name, alias) in links.items()
]
def _get_volumes_from(self): def _get_volumes_from(self):
return [build_volume_from(spec) for spec in self.volumes_from] return [build_volume_from(spec) for spec in self.volumes_from]

View File

@ -7,7 +7,6 @@ import tempfile
from os import path from os import path
from docker.errors import APIError from docker.errors import APIError
from pytest import mark
from six import StringIO from six import StringIO
from six import text_type from six import text_type
@ -372,7 +371,6 @@ class ServiceTest(DockerClientTestCase):
create_and_start_container(db) create_and_start_container(db)
self.assertEqual(db.containers()[0].environment['FOO'], 'BAR') self.assertEqual(db.containers()[0].environment['FOO'], 'BAR')
@mark.skipif(True, reason="Engine returns error - needs investigating")
def test_start_container_creates_links(self): def test_start_container_creates_links(self):
db = self.create_service('db') db = self.create_service('db')
web = self.create_service('web', links=[(db, None)]) web = self.create_service('web', links=[(db, None)])
@ -389,7 +387,6 @@ class ServiceTest(DockerClientTestCase):
'db']) 'db'])
) )
@mark.skipif(True, reason="Engine returns error - needs investigating")
def test_start_container_creates_links_with_names(self): def test_start_container_creates_links_with_names(self):
db = self.create_service('db') db = self.create_service('db')
web = self.create_service('web', links=[(db, 'custom_link_name')]) web = self.create_service('web', links=[(db, 'custom_link_name')])
@ -433,7 +430,6 @@ class ServiceTest(DockerClientTestCase):
c = create_and_start_container(db) c = create_and_start_container(db)
self.assertEqual(set(get_links(c)), set([])) self.assertEqual(set(get_links(c)), set([]))
@mark.skipif(True, reason="Engine returns error - needs investigating")
def test_start_one_off_container_creates_links_to_its_own_service(self): def test_start_one_off_container_creates_links_to_its_own_service(self):
db = self.create_service('db') db = self.create_service('db')