Merge pull request #1830 from mhank/1822-reformat-hosts

Fix format in which hosts are being stored for Swarm services
This commit is contained in:
Joffrey F 2017-12-13 16:26:42 -08:00 committed by GitHub
commit a916bfdde2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View File

@ -137,7 +137,7 @@ class ContainerSpec(dict):
if labels is not None:
self['Labels'] = labels
if hosts is not None:
self['Hosts'] = format_extra_hosts(hosts)
self['Hosts'] = format_extra_hosts(hosts, task=True)
if mounts is not None:
parsed_mounts = []

View File

@ -571,7 +571,13 @@ def format_environment(environment):
return [format_env(*var) for var in six.iteritems(environment)]
def format_extra_hosts(extra_hosts):
def format_extra_hosts(extra_hosts, task=False):
# Use format dictated by Swarm API if container is part of a task
if task:
return [
'{} {}'.format(v, k) for k, v in sorted(six.iteritems(extra_hosts))
]
return [
'{}:{}'.format(k, v) for k, v in sorted(six.iteritems(extra_hosts))
]

View File

@ -588,8 +588,8 @@ class ServiceTest(BaseAPIIntegrationTest):
assert 'Hosts' in svc_info['Spec']['TaskTemplate']['ContainerSpec']
hosts = svc_info['Spec']['TaskTemplate']['ContainerSpec']['Hosts']
assert len(hosts) == 2
assert 'foobar:127.0.0.1' in hosts
assert 'baz:8.8.8.8' in hosts
assert '127.0.0.1 foobar' in hosts
assert '8.8.8.8 baz' in hosts
@requires_api_version('1.25')
def test_create_service_with_hostname(self):