diff options
author | Joffrey F <joffrey@docker.com> | 2018-08-09 15:56:11 -0700 |
---|---|---|
committer | Joffrey F <joffrey@docker.com> | 2018-08-09 15:56:11 -0700 |
commit | 14524f19e2fd2d1c570453d530ae71b1d39dc9fb (patch) | |
tree | 0510b42cbeaf8b46f75ce4625c776cd70538e3cc | |
parent | 0c72cd62418d98b51fd6b5cac069e83e087a0125 (diff) | |
download | docker-py-14524f19e2fd2d1c570453d530ae71b1d39dc9fb.tar.gz |
Add version checks and test
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r-- | docker/api/service.py | 6 | ||||
-rw-r--r-- | docker/types/services.py | 5 | ||||
-rw-r--r-- | 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 03b0ca6..1dbe269 100644 --- a/docker/api/service.py +++ b/docker/api/service.py @@ -18,6 +18,12 @@ def _check_api_features(version, task_template, update_config, endpoint_spec): 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 2940763..a883f3f 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 @@ class UpdateConfig(dict): 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 85f9dcc..ba2ed91 100644 --- a/tests/integration/api_service_test.py +++ b/tests/integration/api_service_test.py @@ -281,6 +281,20 @@ class ServiceTest(BaseAPIIntegrationTest): 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']) |