From f31b8e08b24f1c19c156caf5137ca18159f32df0 Mon Sep 17 00:00:00 2001 From: Hannes Ljungberg Date: Thu, 2 Jan 2020 15:23:36 +0100 Subject: [PATCH] docker_swarm_service: Fix parsing of Healthcheck.StartPeriod (#66151) * Parse Healthcheck.StartPeriod properly * Add changelog fragment * Use proper markup in changelog Co-Authored-By: Felix Fontein Co-authored-by: Felix Fontein --- ...er_swarm_service-healthcheck-start-period.yml | 2 ++ .../modules/cloud/docker/docker_swarm_service.py | 16 +++++++++++----- .../docker_swarm_service/tasks/tests/options.yml | 6 ++++-- 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/66151-docker_swarm_service-healthcheck-start-period.yml diff --git a/changelogs/fragments/66151-docker_swarm_service-healthcheck-start-period.yml b/changelogs/fragments/66151-docker_swarm_service-healthcheck-start-period.yml new file mode 100644 index 0000000000..269efb86e4 --- /dev/null +++ b/changelogs/fragments/66151-docker_swarm_service-healthcheck-start-period.yml @@ -0,0 +1,2 @@ +bugfixes: +- "docker_swarm_service - fix task always reporting as changed when using ``healthcheck.start_period``." diff --git a/lib/ansible/modules/cloud/docker/docker_swarm_service.py b/lib/ansible/modules/cloud/docker/docker_swarm_service.py index e4d2f3f100..359f84972e 100644 --- a/lib/ansible/modules/cloud/docker/docker_swarm_service.py +++ b/lib/ansible/modules/cloud/docker/docker_swarm_service.py @@ -2270,10 +2270,16 @@ class DockerServiceManager(object): healthcheck_data = task_template_data['ContainerSpec'].get('Healthcheck') if healthcheck_data: - options = ['test', 'interval', 'timeout', 'start_period', 'retries'] + options = { + 'Test': 'test', + 'Interval': 'interval', + 'Timeout': 'timeout', + 'StartPeriod': 'start_period', + 'Retries': 'retries' + } healthcheck = dict( - (key.lower(), value) for key, value in healthcheck_data.items() - if value is not None and key.lower() in options + (options[key], value) for key, value in healthcheck_data.items() + if value is not None and key in options ) ds.healthcheck = healthcheck @@ -2882,8 +2888,8 @@ def main(): usage_msg='set publish.mode' ), healthcheck_start_period=dict( - docker_py_version='2.4.0', - docker_api_version='1.25', + docker_py_version='2.6.0', + docker_api_version='1.29', detect_usage=_detect_healthcheck_start_period, usage_msg='set healthcheck.start_period' ), diff --git a/test/integration/targets/docker_swarm_service/tasks/tests/options.yml b/test/integration/targets/docker_swarm_service/tasks/tests/options.yml index 035dc08d8e..1f805bacc3 100644 --- a/test/integration/targets/docker_swarm_service/tasks/tests/options.yml +++ b/test/integration/targets/docker_swarm_service/tasks/tests/options.yml @@ -909,6 +909,7 @@ timeout: 2s interval: 0h0m2s3ms4us retries: 2 + start_period: 20s register: healthcheck_1 ignore_errors: yes @@ -926,6 +927,7 @@ timeout: 2s interval: 0h0m2s3ms4us retries: 2 + start_period: 20s register: healthcheck_2 ignore_errors: yes @@ -1029,12 +1031,12 @@ - healthcheck_7 is not changed - healthcheck_8 is changed - healthcheck_9 is not changed - when: docker_api_version is version('1.25', '>=') and docker_py_version is version('2.6.0', '>=') + when: docker_api_version is version('1.29', '>=') and docker_py_version is version('2.6.0', '>=') - assert: that: - healthcheck_1 is failed - "'Minimum version required' in healthcheck_1.msg" - when: docker_api_version is version('1.25', '<') or docker_py_version is version('2.6.0', '<') + when: docker_api_version is version('1.29', '<') or docker_py_version is version('2.6.0', '<') ################################################################### ## hostname #######################################################