Fix ports sorting on Python 3

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-06-23 15:04:18 -07:00 committed by Joffrey F
parent c38eaeaba3
commit f2054f1a7d
2 changed files with 17 additions and 1 deletions

View File

@ -959,7 +959,7 @@ def merge_ports(md, base, override):
merged = parse_sequence_func(md.base.get(field, []))
merged.update(parse_sequence_func(md.override.get(field, [])))
md[field] = [item for item in sorted(merged.values())]
md[field] = [item for item in sorted(merged.values(), key=lambda x: x.target)]
def merge_build(output, base, override):

View File

@ -1615,6 +1615,22 @@ class ConfigTest(unittest.TestCase):
'ports': types.ServicePort.parse('5432')
}
def test_merge_service_dicts_ports_sorting(self):
base = {
'ports': [5432]
}
override = {
'image': 'alpine:edge',
'ports': ['5432/udp']
}
actual = config.merge_service_dicts_from_files(
base,
override,
DEFAULT_VERSION)
assert len(actual['ports']) == 2
assert types.ServicePort.parse('5432')[0] in actual['ports']
assert types.ServicePort.parse('5432/udp')[0] in actual['ports']
def test_merge_service_dicts_heterogeneous_volumes(self):
base = {
'volumes': ['/a:/b', '/x:/z'],