mirror of https://github.com/docker/compose.git
Test network_aliases feature
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
2f7a77e954
commit
c686be8fd3
|
@ -73,7 +73,9 @@ class Project(object):
|
||||||
|
|
||||||
service_dict.pop('networks', None)
|
service_dict.pop('networks', None)
|
||||||
links = project.get_links(service_dict)
|
links = project.get_links(service_dict)
|
||||||
network_mode = project.get_network_mode(service_dict, service_networks.keys())
|
network_mode = project.get_network_mode(
|
||||||
|
service_dict, list(service_networks.keys())
|
||||||
|
)
|
||||||
volumes_from = get_volumes_from(project, service_dict)
|
volumes_from = get_volumes_from(project, service_dict)
|
||||||
|
|
||||||
if config_data.version != V1:
|
if config_data.version != V1:
|
||||||
|
|
|
@ -445,6 +445,33 @@ class CLITestCase(DockerClientTestCase):
|
||||||
|
|
||||||
assert networks[0]['Options']['com.docker.network.bridge.enable_icc'] == 'false'
|
assert networks[0]['Options']['com.docker.network.bridge.enable_icc'] == 'false'
|
||||||
|
|
||||||
|
def test_up_with_network_aliases(self):
|
||||||
|
filename = 'network-aliases.yml'
|
||||||
|
self.base_dir = 'tests/fixtures/networks'
|
||||||
|
self.dispatch(['-f', filename, 'up', '-d'], None)
|
||||||
|
back_name = '{}_back'.format(self.project.name)
|
||||||
|
front_name = '{}_front'.format(self.project.name)
|
||||||
|
|
||||||
|
networks = [
|
||||||
|
n for n in self.client.networks()
|
||||||
|
if n['Name'].startswith('{}_'.format(self.project.name))
|
||||||
|
]
|
||||||
|
|
||||||
|
# Two networks were created: back and front
|
||||||
|
assert sorted(n['Name'] for n in networks) == [back_name, front_name]
|
||||||
|
web_container = self.project.get_service('web').containers()[0]
|
||||||
|
|
||||||
|
back_aliases = web_container.get(
|
||||||
|
'NetworkSettings.Networks.{}.Aliases'.format(back_name)
|
||||||
|
)
|
||||||
|
assert 'web' in back_aliases
|
||||||
|
front_aliases = web_container.get(
|
||||||
|
'NetworkSettings.Networks.{}.Aliases'.format(front_name)
|
||||||
|
)
|
||||||
|
assert 'web' in front_aliases
|
||||||
|
assert 'forward_facing' in front_aliases
|
||||||
|
assert 'ahead' in front_aliases
|
||||||
|
|
||||||
@v2_only()
|
@v2_only()
|
||||||
def test_up_with_networks(self):
|
def test_up_with_networks(self):
|
||||||
self.base_dir = 'tests/fixtures/networks'
|
self.base_dir = 'tests/fixtures/networks'
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
version: "2"
|
||||||
|
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
image: busybox
|
||||||
|
command: top
|
||||||
|
networks:
|
||||||
|
- front
|
||||||
|
- back
|
||||||
|
|
||||||
|
network_aliases:
|
||||||
|
front:
|
||||||
|
- forward_facing
|
||||||
|
- ahead
|
||||||
|
|
||||||
|
networks:
|
||||||
|
front: {}
|
||||||
|
back: {}
|
|
@ -543,6 +543,27 @@ class ConfigTest(unittest.TestCase):
|
||||||
assert services[1]['name'] == 'db'
|
assert services[1]['name'] == 'db'
|
||||||
assert services[2]['name'] == 'web'
|
assert services[2]['name'] == 'web'
|
||||||
|
|
||||||
|
def test_invalid_network_alias(self):
|
||||||
|
config_details = build_config_details({
|
||||||
|
'version': '2',
|
||||||
|
'services': {
|
||||||
|
'web': {
|
||||||
|
'image': 'busybox',
|
||||||
|
'networks': ['hello'],
|
||||||
|
'network_aliases': {
|
||||||
|
'world': ['planet', 'universe']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'networks': {
|
||||||
|
'hello': {},
|
||||||
|
'world': {}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
with pytest.raises(ConfigurationError) as exc:
|
||||||
|
config.load(config_details)
|
||||||
|
assert 'not declared in the networks list' in exc.exconly()
|
||||||
|
|
||||||
def test_config_build_configuration(self):
|
def test_config_build_configuration(self):
|
||||||
service = config.load(
|
service = config.load(
|
||||||
build_config_details(
|
build_config_details(
|
||||||
|
|
Loading…
Reference in New Issue