mirror of https://github.com/docker/compose.git
Extract link names into a function.
Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
parent
805f6a7683
commit
db31adc208
|
@ -304,7 +304,7 @@ class TopLevelCommand(Command):
|
|||
log.warn(INSECURE_SSL_WARNING)
|
||||
|
||||
if not options['--no-deps']:
|
||||
deps = service.get_linked_names()
|
||||
deps = service.get_linked_service_names()
|
||||
|
||||
if len(deps) > 0:
|
||||
project.up(
|
||||
|
|
|
@ -477,19 +477,22 @@ class Service(object):
|
|||
return {
|
||||
'options': self.options,
|
||||
'image_id': self.image()['Id'],
|
||||
'links': [(service.name, alias) for service, alias in self.links],
|
||||
'links': self.get_link_names(),
|
||||
'net': self.net.id,
|
||||
'volumes_from': self.get_volumes_from_names(),
|
||||
}
|
||||
|
||||
def get_dependency_names(self):
|
||||
net_name = self.net.service_name
|
||||
return (self.get_linked_names() +
|
||||
return (self.get_linked_service_names() +
|
||||
self.get_volumes_from_names() +
|
||||
([net_name] if net_name else []))
|
||||
|
||||
def get_linked_names(self):
|
||||
return [s.name for (s, _) in self.links]
|
||||
def get_linked_service_names(self):
|
||||
return [service.name for (service, _) in self.links]
|
||||
|
||||
def get_link_names(self):
|
||||
return [(service.name, alias) for service, alias in self.links]
|
||||
|
||||
def get_volumes_from_names(self):
|
||||
return [s.name for s in self.volumes_from if isinstance(s, Service)]
|
||||
|
@ -776,7 +779,7 @@ class Net(object):
|
|||
|
||||
|
||||
class ContainerNet(object):
|
||||
"""A network mode that uses a containers network stack."""
|
||||
"""A network mode that uses a container's network stack."""
|
||||
|
||||
service_name = None
|
||||
|
||||
|
|
|
@ -112,7 +112,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
|
||||
web = project.get_service('web')
|
||||
net = project.get_service('net')
|
||||
self.assertEqual(web._get_net(), 'container:' + net.containers()[0].id)
|
||||
self.assertEqual(web.net.mode, 'container:' + net.containers()[0].id)
|
||||
|
||||
def test_net_from_container(self):
|
||||
net_container = Container.create(
|
||||
|
@ -138,7 +138,7 @@ class ProjectTest(DockerClientTestCase):
|
|||
project.up()
|
||||
|
||||
web = project.get_service('web')
|
||||
self.assertEqual(web._get_net(), 'container:' + net_container.id)
|
||||
self.assertEqual(web.net.mode, 'container:' + net_container.id)
|
||||
|
||||
def test_start_stop_kill_remove(self):
|
||||
web = self.create_service('web')
|
||||
|
|
|
@ -9,6 +9,7 @@ import tempfile
|
|||
import shutil
|
||||
from six import StringIO, text_type
|
||||
|
||||
from .testcases import DockerClientTestCase
|
||||
from compose import __version__
|
||||
from compose.const import (
|
||||
LABEL_CONTAINER_NUMBER,
|
||||
|
@ -17,14 +18,12 @@ from compose.const import (
|
|||
LABEL_SERVICE,
|
||||
LABEL_VERSION,
|
||||
)
|
||||
from compose.service import (
|
||||
ConfigError,
|
||||
ConvergencePlan,
|
||||
Service,
|
||||
build_extra_hosts,
|
||||
)
|
||||
from compose.container import Container
|
||||
from .testcases import DockerClientTestCase
|
||||
from compose.service import build_extra_hosts
|
||||
from compose.service import ConfigError
|
||||
from compose.service import ConvergencePlan
|
||||
from compose.service import Net
|
||||
from compose.service import Service
|
||||
|
||||
|
||||
def create_and_start_container(service, **override_options):
|
||||
|
@ -743,17 +742,17 @@ class ServiceTest(DockerClientTestCase):
|
|||
self.assertEqual(list(container.inspect()['HostConfig']['PortBindings'].keys()), ['8000/tcp'])
|
||||
|
||||
def test_network_mode_none(self):
|
||||
service = self.create_service('web', net='none')
|
||||
service = self.create_service('web', net=Net('none'))
|
||||
container = create_and_start_container(service)
|
||||
self.assertEqual(container.get('HostConfig.NetworkMode'), 'none')
|
||||
|
||||
def test_network_mode_bridged(self):
|
||||
service = self.create_service('web', net='bridge')
|
||||
service = self.create_service('web', net=Net('bridge'))
|
||||
container = create_and_start_container(service)
|
||||
self.assertEqual(container.get('HostConfig.NetworkMode'), 'bridge')
|
||||
|
||||
def test_network_mode_host(self):
|
||||
service = self.create_service('web', net='host')
|
||||
service = self.create_service('web', net=Net('host'))
|
||||
container = create_and_start_container(service)
|
||||
self.assertEqual(container.get('HostConfig.NetworkMode'), 'host')
|
||||
|
||||
|
|
Loading…
Reference in New Issue