diff options
| author | Michael Hankin <mjhankin1@gmail.com> | 2017-12-12 15:49:07 -0600 |
|---|---|---|
| committer | Michael Hankin <mjhankin1@gmail.com> | 2017-12-12 15:49:07 -0600 |
| commit | 61bc8bea7f4f4cc9e57da2a9ae36ce5002e129f9 (patch) | |
| tree | 4379bd5b1651cbd00685c5ef3482629246c99b6e | |
| parent | d8f996f969e9f8c8ef0c0409d2ee1d458dc2c46f (diff) | |
| download | docker-py-61bc8bea7f4f4cc9e57da2a9ae36ce5002e129f9.tar.gz | |
Add support for order property when updating a service
Signed-off-by: Michael Hankin <mjhankin1@gmail.com>
| -rw-r--r-- | docker/api/service.py | 4 | ||||
| -rw-r--r-- | docker/types/services.py | 11 | ||||
| -rw-r--r-- | tests/integration/api_service_test.py | 18 |
3 files changed, 32 insertions, 1 deletions
diff --git a/docker/api/service.py b/docker/api/service.py index 4c10ef8..df899f5 100644 --- a/docker/api/service.py +++ b/docker/api/service.py @@ -19,6 +19,10 @@ def _check_api_features(version, task_template, update_config): if 'Monitor' in update_config: raise_version_error('UpdateConfig.monitor', '1.25') + if utils.version_lt(version, '1.29'): + if 'Order' in update_config: + raise_version_error('UpdateConfig.order', '1.29') + if task_template is not None: if 'ForceUpdate' in task_template and utils.version_lt( version, '1.25'): diff --git a/docker/types/services.py b/docker/types/services.py index 9031e60..14e2cc3 100644 --- a/docker/types/services.py +++ b/docker/types/services.py @@ -334,9 +334,12 @@ class UpdateConfig(dict): max_failure_ratio (float): The fraction of tasks that may fail during an update before the failure action is invoked, specified as a floating point number between 0 and 1. Default: 0 + order (string): Specifies the order of operations when rolling out an + updated task. Either ``start_first`` or ``stop_first`` are accepted. + Default: ``stop_first`` """ def __init__(self, parallelism=0, delay=None, failure_action='continue', - monitor=None, max_failure_ratio=None): + monitor=None, max_failure_ratio=None, order='stop-first'): self['Parallelism'] = parallelism if delay is not None: self['Delay'] = delay @@ -360,6 +363,12 @@ class UpdateConfig(dict): ) self['MaxFailureRatio'] = max_failure_ratio + if order not in ('start-first', 'stop-first'): + raise errors.InvalidArgument( + 'order must be either `start-first` or `stop-first`' + ) + self['Order'] = order + class RestartConditionTypesEnum(object): _values = ( diff --git a/tests/integration/api_service_test.py b/tests/integration/api_service_test.py index b931154..fb57f63 100644 --- a/tests/integration/api_service_test.py +++ b/tests/integration/api_service_test.py @@ -386,6 +386,24 @@ class ServiceTest(BaseAPIIntegrationTest): assert 'Env' in con_spec assert con_spec['Env'] == ['DOCKER_PY_TEST=1'] + @requires_api_version('1.29') + def test_create_service_with_update_order(self): + container_spec = docker.types.ContainerSpec(BUSYBOX, ['true']) + task_tmpl = docker.types.TaskTemplate(container_spec) + update_config = docker.types.UpdateConfig( + parallelism=10, delay=5, order='start-first' + ) + 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['Parallelism'] == uc['Parallelism'] + assert update_config['Delay'] == uc['Delay'] + assert update_config['Order'] == uc['Order'] + @requires_api_version('1.25') def test_create_service_with_tty(self): container_spec = docker.types.ContainerSpec( |
