From 3112d3920988fde5afa35d2dadbb5298db3a77da Mon Sep 17 00:00:00 2001 From: Nikolay Murga Date: Fri, 20 Jul 2018 12:53:44 +0300 Subject: [PATCH 1/3] Add 'rollback' command as allowed for failure_action Signed-off-by: Nikolay Murga --- docker/types/services.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/types/services.py b/docker/types/services.py index 31f4750f45..a914cef691 100644 --- a/docker/types/services.py +++ b/docker/types/services.py @@ -371,7 +371,7 @@ class UpdateConfig(dict): delay (int): Amount of time between updates. failure_action (string): Action to take if an updated task fails to run, or stops running during the update. Acceptable values are - ``continue`` and ``pause``. Default: ``continue`` + ``continue``, ``rollback`` and ``pause``. Default: ``continue`` monitor (int): Amount of time to monitor each updated task for failures, in nanoseconds. max_failure_ratio (float): The fraction of tasks that may fail during @@ -385,7 +385,7 @@ def __init__(self, parallelism=0, delay=None, failure_action='continue', self['Parallelism'] = parallelism if delay is not None: self['Delay'] = delay - if failure_action not in ('pause', 'continue'): + if failure_action not in ('pause', 'continue', 'rollback'): raise errors.InvalidArgument( 'failure_action must be either `pause` or `continue`.' ) From 24fff59bd95d077a523496a942225a074707bc08 Mon Sep 17 00:00:00 2001 From: Nikolay Murga Date: Fri, 20 Jul 2018 13:20:19 +0300 Subject: [PATCH 2/3] Add documentation for delay property Signed-off-by: Nikolay Murga --- docker/types/services.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/types/services.py b/docker/types/services.py index a914cef691..294076384b 100644 --- a/docker/types/services.py +++ b/docker/types/services.py @@ -368,7 +368,7 @@ class UpdateConfig(dict): parallelism (int): Maximum number of tasks to be updated in one iteration (0 means unlimited parallelism). Default: 0. - delay (int): Amount of time between updates. + delay (int): Amount of time between updates, in nanoseconds. failure_action (string): Action to take if an updated task fails to run, or stops running during the update. Acceptable values are ``continue``, ``rollback`` and ``pause``. Default: ``continue`` From 14524f19e2fd2d1c570453d530ae71b1d39dc9fb Mon Sep 17 00:00:00 2001 From: Joffrey F Date: Thu, 9 Aug 2018 15:56:11 -0700 Subject: [PATCH 3/3] Add version checks and test Signed-off-by: Joffrey F --- docker/api/service.py | 6 ++++++ docker/types/services.py | 5 +++-- tests/integration/api_service_test.py | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docker/api/service.py b/docker/api/service.py index 03b0ca6ea2..1dbe2697f1 100644 --- a/docker/api/service.py +++ b/docker/api/service.py @@ -18,6 +18,12 @@ def raise_version_error(param, min_version): if 'Monitor' in update_config: raise_version_error('UpdateConfig.monitor', '1.25') + if utils.version_lt(version, '1.28'): + if update_config.get('FailureAction') == 'rollback': + raise_version_error( + 'UpdateConfig.failure_action rollback', '1.28' + ) + if utils.version_lt(version, '1.29'): if 'Order' in update_config: raise_version_error('UpdateConfig.order', '1.29') diff --git a/docker/types/services.py b/docker/types/services.py index 294076384b..a883f3ff7d 100644 --- a/docker/types/services.py +++ b/docker/types/services.py @@ -371,7 +371,8 @@ class UpdateConfig(dict): delay (int): Amount of time between updates, in nanoseconds. failure_action (string): Action to take if an updated task fails to run, or stops running during the update. Acceptable values are - ``continue``, ``rollback`` and ``pause``. Default: ``continue`` + ``continue``, ``pause``, as well as ``rollback`` since API v1.28. + Default: ``continue`` monitor (int): Amount of time to monitor each updated task for failures, in nanoseconds. max_failure_ratio (float): The fraction of tasks that may fail during @@ -387,7 +388,7 @@ def __init__(self, parallelism=0, delay=None, failure_action='continue', self['Delay'] = delay if failure_action not in ('pause', 'continue', 'rollback'): raise errors.InvalidArgument( - 'failure_action must be either `pause` or `continue`.' + 'failure_action must be one of `pause`, `continue`, `rollback`' ) self['FailureAction'] = failure_action diff --git a/tests/integration/api_service_test.py b/tests/integration/api_service_test.py index 85f9dccf26..ba2ed91f72 100644 --- a/tests/integration/api_service_test.py +++ b/tests/integration/api_service_test.py @@ -281,6 +281,20 @@ def test_create_service_with_update_config(self): assert update_config['Delay'] == uc['Delay'] assert update_config['FailureAction'] == uc['FailureAction'] + @requires_api_version('1.28') + def test_create_service_with_failure_action_rollback(self): + container_spec = docker.types.ContainerSpec(BUSYBOX, ['true']) + task_tmpl = docker.types.TaskTemplate(container_spec) + update_config = docker.types.UpdateConfig(failure_action='rollback') + name = self.get_service_name() + svc_id = self.client.create_service( + task_tmpl, update_config=update_config, name=name + ) + svc_info = self.client.inspect_service(svc_id) + assert 'UpdateConfig' in svc_info['Spec'] + uc = svc_info['Spec']['UpdateConfig'] + assert update_config['FailureAction'] == uc['FailureAction'] + @requires_api_version('1.25') def test_create_service_with_update_config_monitor(self): container_spec = docker.types.ContainerSpec('busybox', ['true'])