Skip to content
Prev Previous commit
Next Next commit
Add version checks and test
Signed-off-by: Joffrey F <[email protected]>
  • Loading branch information
shin- committed Aug 10, 2018
commit e4b509ecace12dab1244b3dbcc33196d5e59e9d3
6 changes: 6 additions & 0 deletions docker/api/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
5 changes: 3 additions & 2 deletions docker/types/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
14 changes: 14 additions & 0 deletions tests/integration/api_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down