Unit test for skipping network disconnect.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-04-15 15:42:36 -04:00 committed by Joffrey F
parent 5852db4d72
commit 2a8c2c8ad6
3 changed files with 46 additions and 5 deletions

View File

@ -535,7 +535,7 @@ class Service(object):
def _get_aliases(self, network, container=None):
if container and container.labels.get(LABEL_ONE_OFF) == "True":
return set()
return []
return list(
{self.name} |

View File

@ -565,7 +565,11 @@ class ProjectTest(DockerClientTestCase):
'name': 'web',
'image': 'busybox:latest',
'command': 'top',
'networks': {'foo': None, 'bar': None, 'baz': None},
'networks': {
'foo': None,
'bar': None,
'baz': {'aliases': ['extra']},
},
}],
volumes={},
networks={
@ -581,15 +585,23 @@ class ProjectTest(DockerClientTestCase):
config_data=config_data,
)
project.up()
self.assertEqual(len(project.containers()), 1)
containers = project.containers()
assert len(containers) == 1
container, = containers
for net_name in ['foo', 'bar', 'baz']:
full_net_name = 'composetest_{}'.format(net_name)
network_data = self.client.inspect_network(full_net_name)
self.assertEqual(network_data['Name'], full_net_name)
assert network_data['Name'] == full_net_name
aliases_key = 'NetworkSettings.Networks.{net}.Aliases'
assert 'web' in container.get(aliases_key.format(net='composetest_foo'))
assert 'web' in container.get(aliases_key.format(net='composetest_baz'))
assert 'extra' in container.get(aliases_key.format(net='composetest_baz'))
foo_data = self.client.inspect_network('composetest_foo')
self.assertEqual(foo_data['Driver'], 'bridge')
assert foo_data['Driver'] == 'bridge'
@v2_only()
def test_up_with_ipam_config(self):

View File

@ -643,6 +643,35 @@ class ServiceTest(unittest.TestCase):
assert service.image_name == 'testing_foo'
class TestServiceNetwork(object):
def test_connect_container_to_networks_short_aliase_exists(self):
mock_client = mock.create_autospec(docker.Client)
service = Service(
'db',
mock_client,
'myproject',
image='foo',
networks={'project_default': {}})
container = Container(
None,
{
'Id': 'abcdef',
'NetworkSettings': {
'Networks': {
'project_default': {
'Aliases': ['analias', 'abcdef'],
},
},
},
},
True)
service.connect_container_to_networks(container)
assert not mock_client.disconnect_container_from_network.call_count
assert not mock_client.connect_container_to_network.call_count
def sort_by_name(dictionary_list):
return sorted(dictionary_list, key=lambda k: k['name'])