From d429a823ed33032d1980903922251996c551ca5c Mon Sep 17 00:00:00 2001 From: Hannes Ljungberg Date: Fri, 18 Jan 2019 21:50:31 +0100 Subject: [PATCH] Make PlacementPreference build correct context Signed-off-by: Hannes Ljungberg --- docker/types/services.py | 2 +- tests/integration/api_service_test.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docker/types/services.py b/docker/types/services.py index ac1c181a90..a0721f607b 100644 --- a/docker/types/services.py +++ b/docker/types/services.py @@ -692,7 +692,7 @@ def __init__(self, strategy, descriptor): 'PlacementPreference strategy value is invalid ({}):' ' must be "spread".'.format(strategy) ) - self['SpreadOver'] = descriptor + self['Spread'] = {'SpreadDescriptor': descriptor} class DNSConfig(dict): diff --git a/tests/integration/api_service_test.py b/tests/integration/api_service_test.py index a53ca1c836..57a8d331ce 100644 --- a/tests/integration/api_service_test.py +++ b/tests/integration/api_service_test.py @@ -427,6 +427,21 @@ def test_create_service_with_placement_preferences(self): assert 'Placement' in svc_info['Spec']['TaskTemplate'] assert svc_info['Spec']['TaskTemplate']['Placement'] == placemt + @requires_api_version('1.27') + def test_create_service_with_placement_preferences_tuple(self): + container_spec = docker.types.ContainerSpec(BUSYBOX, ['true']) + placemt = docker.types.Placement(preferences=( + ('spread', 'com.dockerpy.test'), + )) + task_tmpl = docker.types.TaskTemplate( + container_spec, placement=placemt + ) + name = self.get_service_name() + svc_id = self.client.create_service(task_tmpl, name=name) + svc_info = self.client.inspect_service(svc_id) + assert 'Placement' in svc_info['Spec']['TaskTemplate'] + assert svc_info['Spec']['TaskTemplate']['Placement'] == placemt + def test_create_service_with_endpoint_spec(self): container_spec = docker.types.ContainerSpec(BUSYBOX, ['true']) task_tmpl = docker.types.TaskTemplate(container_spec)