Skip to content

Commit

Permalink
Backport of ansible-collections/community.docker#88 to stable-1. (#1982)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein authored Mar 8, 2021
1 parent 1e1a843 commit a22113c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "docker_container - fix healthcheck disabling idempotency issue with strict comparison (https://github.com/ansible-collections/community.docker/issues/85)."
6 changes: 6 additions & 0 deletions plugins/modules/cloud/docker/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2293,6 +2293,12 @@ def has_different_configuration(self, image):
match = self._compare(getattr(self.parameters, key), value, compare)

if not match:
if key == 'expected_healthcheck' and config_mapping['disable_healthcheck'] and self.parameters.disable_healthcheck:
# If the healthcheck is disabled (both in parameters and for the current container), and the user
# requested strict comparison for healthcheck, the comparison will fail. That's why we ignore the
# expected_healthcheck comparison in this case.
continue

# no match. record the differences
p = getattr(self.parameters, key)
c = value
Expand Down
24 changes: 20 additions & 4 deletions tests/integration/targets/docker_container/tasks/tests/options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,21 @@
register: healthcheck_6
ignore_errors: yes

- name: healthcheck (disabled, idempotency, strict)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
healthcheck:
test:
- NONE
force_kill: yes
comparisons:
'*': strict
register: healthcheck_7
ignore_errors: yes

- name: healthcheck (string in healthcheck test, changed)
docker_container:
image: "{{ docker_test_image_alpine }}"
Expand All @@ -1672,7 +1687,7 @@
healthcheck:
test: "sleep 1"
force_kill: yes
register: healthcheck_7
register: healthcheck_8
ignore_errors: yes

- name: healthcheck (string in healthcheck test, idempotency)
Expand All @@ -1684,7 +1699,7 @@
healthcheck:
test: "sleep 1"
force_kill: yes
register: healthcheck_8
register: healthcheck_9
ignore_errors: yes

- name: cleanup
Expand All @@ -1702,8 +1717,9 @@
- healthcheck_4 is not changed
- healthcheck_5 is changed
- healthcheck_6 is not changed
- healthcheck_7 is changed
- healthcheck_8 is not changed
- healthcheck_7 is not changed
- healthcheck_8 is changed
- healthcheck_9 is not changed
when: docker_py_version is version('2.0.0', '>=')
- assert:
that:
Expand Down

0 comments on commit a22113c

Please sign in to comment.