Unverified Kaydet (Commit) a916bfdd authored tarafından Joffrey F's avatar Joffrey F Kaydeden (comit) GitHub

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

Fix format in which hosts are being stored for Swarm services
......@@ -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 = []
......
......@@ -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))
]
......
......@@ -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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment