Skip to content

Commit 7e79524

Browse files
authored
Merge pull request #2108 from docker/NikolayMurha-master
Add 'rollback' command as allowed for failure_action
2 parents cc76663 + 14524f1 commit 7e79524

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,11 @@ class UpdateConfig(dict):
368368
369369
parallelism (int): Maximum number of tasks to be updated in one
370370
iteration (0 means unlimited parallelism). Default: 0.
371-
delay (int): Amount of time between updates.
371+
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`` 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
@@ -385,9 +386,9 @@ def __init__(self, parallelism=0, delay=None, failure_action='continue',
385386
self['Parallelism'] = parallelism
386387
if delay is not None:
387388
self['Delay'] = delay
388-
if failure_action not in ('pause', 'continue'):
389+
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)