Skip to content

Commit e4b509e

Browse files
committed
Add version checks and test
Signed-off-by: Joffrey F <[email protected]>
1 parent c2c9ccd commit e4b509e

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

docker/api/service.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ def raise_version_error(param, min_version):
1818
if 'Monitor' in update_config:
1919
raise_version_error('UpdateConfig.monitor', '1.25')
2020

21+
if utils.version_lt(version, '1.28'):
22+
if update_config.get('FailureAction') == 'rollback':
23+
raise_version_error(
24+
'UpdateConfig.failure_action rollback', '1.28'
25+
)
26+
2127
if utils.version_lt(version, '1.29'):
2228
if 'Order' in update_config:
2329
raise_version_error('UpdateConfig.order', '1.29')

docker/types/services.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ class UpdateConfig(dict):
371371
delay (int): Amount of time between updates, in nanoseconds.
372372
failure_action (string): Action to take if an updated task fails to
373373
run, or stops running during the update. Acceptable values are
374-
``continue``, ``rollback`` and ``pause``. Default: ``continue``
374+
``continue``, ``pause``, as well as ``rollback`` since API v1.28.
375+
Default: ``continue``
375376
monitor (int): Amount of time to monitor each updated task for
376377
failures, in nanoseconds.
377378
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',
387388
self['Delay'] = delay
388389
if failure_action not in ('pause', 'continue', 'rollback'):
389390
raise errors.InvalidArgument(
390-
'failure_action must be either `pause` or `continue`.'
391+
'failure_action must be one of `pause`, `continue`, `rollback`'
391392
)
392393
self['FailureAction'] = failure_action
393394

tests/integration/api_service_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,20 @@ def test_create_service_with_update_config(self):
281281
assert update_config['Delay'] == uc['Delay']
282282
assert update_config['FailureAction'] == uc['FailureAction']
283283

284+
@requires_api_version('1.28')
285+
def test_create_service_with_failure_action_rollback(self):
286+
container_spec = docker.types.ContainerSpec(BUSYBOX, ['true'])
287+
task_tmpl = docker.types.TaskTemplate(container_spec)
288+
update_config = docker.types.UpdateConfig(failure_action='rollback')
289+
name = self.get_service_name()
290+
svc_id = self.client.create_service(
291+
task_tmpl, update_config=update_config, name=name
292+
)
293+
svc_info = self.client.inspect_service(svc_id)
294+
assert 'UpdateConfig' in svc_info['Spec']
295+
uc = svc_info['Spec']['UpdateConfig']
296+
assert update_config['FailureAction'] == uc['FailureAction']
297+
284298
@requires_api_version('1.25')
285299
def test_create_service_with_update_config_monitor(self):
286300
container_spec = docker.types.ContainerSpec('busybox', ['true'])

0 commit comments

Comments
 (0)