Include networks in the config_hash.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-01-29 16:30:24 -05:00 committed by Aanand Prasad
parent 3e8a4a5dc3
commit 3b1276bd44
6 changed files with 19 additions and 10 deletions

View File

@ -136,7 +136,7 @@ class ProjectNetworks(object):
service_networks = {
network: networks.get(network)
for service in services
for network in service.get('networks', ['default'])
for network in get_network_names_for_service(service)
}
unused = set(networks) - set(service_networks) - {'default'}
if unused:
@ -159,12 +159,15 @@ class ProjectNetworks(object):
network.ensure()
def get_networks(service_dict, network_definitions):
def get_network_names_for_service(service_dict):
if 'network_mode' in service_dict:
return []
return service_dict.get('networks', ['default'])
def get_networks(service_dict, network_definitions):
networks = []
for name in service_dict.pop('networks', ['default']):
for name in get_network_names_for_service(service_dict):
network = network_definitions.get(name)
if network:
networks.append(network.full_name)
@ -172,4 +175,5 @@ def get_networks(service_dict, network_definitions):
raise ConfigurationError(
'Service "{}" uses an undefined network "{}"'
.format(service_dict['name'], name))
return networks

View File

@ -96,6 +96,7 @@ class Project(object):
project.services.append(
Service(
service_dict.pop('name'),
client=client,
project=name,
use_networking=use_networking,

View File

@ -472,6 +472,7 @@ class Service(object):
'image_id': self.image()['Id'],
'links': self.get_link_names(),
'net': self.network_mode.id,
'networks': self.networks,
'volumes_from': [
(v.source.name, v.mode)
for v in self.volumes_from if isinstance(v.source, Service)

View File

@ -406,7 +406,7 @@ class CLITestCase(DockerClientTestCase):
services = self.project.get_services()
network_name = self.project.networks.networks['default']
network_name = self.project.networks.networks['default'].full_name
networks = self.client.networks(names=[network_name])
self.assertEqual(len(networks), 1)
self.assertEqual(networks[0]['Driver'], 'bridge')
@ -440,7 +440,7 @@ class CLITestCase(DockerClientTestCase):
self.dispatch(['-f', filename, 'up', '-d'], None)
network_name = self.project.networks.networks['default']
network_name = self.project.networks.networks['default'].full_name
networks = self.client.networks(names=[network_name])
assert networks[0]['Options']['com.docker.network.bridge.enable_icc'] == 'false'
@ -596,7 +596,7 @@ class CLITestCase(DockerClientTestCase):
self.dispatch(['up', '-d', 'web'], None)
# No network was created
network_name = self.project.networks.networks['default']
network_name = self.project.networks.networks['default'].full_name
networks = self.client.networks(names=[network_name])
assert networks == []

View File

@ -832,7 +832,8 @@ class ProjectTest(DockerClientTestCase):
)
project = Project.from_config(
name='composetest',
config_data=config_data, client=self.client
config_data=config_data,
client=self.client
)
with self.assertRaises(config.ConfigurationError) as e:
project.initialize_volumes()

View File

@ -266,7 +266,7 @@ class ServiceTest(unittest.TestCase):
self.assertEqual(
opts['labels'][LABEL_CONFIG_HASH],
'3c85881a8903b9d73a06c41860c8be08acce1494ab4cf8408375966dccd714de')
'f8bfa1058ad1f4231372a0b1639f0dfdb574dafff4e8d7938049ae993f7cf1fc')
self.assertEqual(
opts['environment'],
{
@ -417,9 +417,10 @@ class ServiceTest(unittest.TestCase):
'options': {'image': 'example.com/foo'},
'links': [('one', 'one')],
'net': 'other',
'networks': [],
'volumes_from': [('two', 'rw')],
}
self.assertEqual(config_dict, expected)
assert config_dict == expected
def test_config_dict_with_network_mode_from_container(self):
self.mock_client.inspect_image.return_value = {'Id': 'abcd'}
@ -437,10 +438,11 @@ class ServiceTest(unittest.TestCase):
'image_id': 'abcd',
'options': {'image': 'example.com/foo'},
'links': [],
'networks': [],
'net': 'aaabbb',
'volumes_from': [],
}
self.assertEqual(config_dict, expected)
assert config_dict == expected
def test_remove_image_none(self):
web = Service('web', image='example', client=self.mock_client)