mirror of
https://github.com/ansible-collections/community.docker.git
synced 2025-12-15 19:42:06 +00:00
Fix idempotency of docker_compose_v2_pull. (#814)
This commit is contained in:
parent
6600f501ae
commit
4bab9a6b0e
2
changelogs/fragments/814-docker_compose_v2_pull-idem.yml
Normal file
2
changelogs/fragments/814-docker_compose_v2_pull-idem.yml
Normal file
@ -0,0 +1,2 @@
|
||||
bugfixes:
|
||||
- "docker_compose_v2_pull - fixing idempotence by checking actual pull progress events instead of service-level pull request when ``policy=always``. This stops the module from reporting ``changed=true`` if no actual change happened when pulling. In check mode, it has to assume that a change happens though (https://github.com/ansible-collections/community.docker/issues/813, https://github.com/ansible-collections/community.docker/pull/814)."
|
||||
@ -409,6 +409,8 @@ def has_changes(events, ignore_service_pull_events=False):
|
||||
if ignore_service_pull_events and event.status in DOCKER_STATUS_PULL:
|
||||
continue
|
||||
return True
|
||||
if event.resource_type == ResourceType.IMAGE_LAYER and event.status in DOCKER_PULL_PROGRESS_WORKING:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@ -31,6 +31,8 @@ extends_documentation_fragment:
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
details:
|
||||
- In check mode, pulling the image does not result in a changed result.
|
||||
diff_mode:
|
||||
support: none
|
||||
|
||||
|
||||
@ -29,6 +29,10 @@ extends_documentation_fragment:
|
||||
attributes:
|
||||
check_mode:
|
||||
support: full
|
||||
details:
|
||||
- If O(policy=always), the module will always indicate a change.
|
||||
Docker Compose does not give any information whether pulling would
|
||||
update the image or not.
|
||||
diff_mode:
|
||||
support: none
|
||||
|
||||
@ -131,7 +135,7 @@ class PullManager(BaseComposeManager):
|
||||
rc, stdout, stderr = self.client.call_cli(*args, cwd=self.project_src)
|
||||
events = self.parse_events(stderr, dry_run=self.check_mode)
|
||||
self.emit_warnings(events)
|
||||
self.update_result(result, events, stdout, stderr)
|
||||
self.update_result(result, events, stdout, stderr, ignore_service_pull_events=self.policy != 'missing' and not self.check_mode)
|
||||
self.update_failed(result, events, args, stdout, stderr, rc)
|
||||
self.cleanup_result(result)
|
||||
return result
|
||||
|
||||
@ -105,6 +105,10 @@
|
||||
policy: missing
|
||||
register: pull_2
|
||||
|
||||
- name: Make sure image is not around
|
||||
docker_image_remove:
|
||||
name: '{{ docker_test_image_alpine }}'
|
||||
|
||||
- name: Pull with policy=always (check)
|
||||
docker_compose_v2_pull:
|
||||
project_src: '{{ project_src }}'
|
||||
@ -118,26 +122,35 @@
|
||||
policy: always
|
||||
register: pull_3
|
||||
|
||||
- name: Pull with policy=always (check, idempotent)
|
||||
docker_compose_v2_pull:
|
||||
project_src: '{{ project_src }}'
|
||||
policy: always
|
||||
check_mode: true
|
||||
register: pull_4_check
|
||||
|
||||
- name: Pull with policy=always (idempotent)
|
||||
docker_compose_v2_pull:
|
||||
project_src: '{{ project_src }}'
|
||||
policy: always
|
||||
register: pull_4
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- pull_1_check is changed
|
||||
- pull_1_check.actions | selectattr('status', 'eq', 'Pulling') | first
|
||||
- pull_1_check.actions | selectattr('status', 'eq', 'Creating') | length == 0
|
||||
- pull_1_check.actions | selectattr('status', 'eq', 'Recreating') | length == 0
|
||||
- pull_1 is changed
|
||||
- pull_1.actions | selectattr('status', 'eq', 'Pulling') | first
|
||||
- pull_1.actions | selectattr('status', 'eq', 'Creating') | length == 0
|
||||
- pull_1.actions | selectattr('status', 'eq', 'Recreating') | length == 0
|
||||
- pull_2_check is not changed
|
||||
- pull_2 is not changed
|
||||
- pull_3_check is changed
|
||||
- pull_3_check.actions | selectattr('status', 'eq', 'Pulling') | first
|
||||
- pull_3_check.actions | selectattr('status', 'eq', 'Creating') | length == 0
|
||||
- pull_3_check.actions | selectattr('status', 'eq', 'Recreating') | length == 0
|
||||
- pull_3 is changed
|
||||
- pull_3.actions | selectattr('status', 'eq', 'Pulling') | first
|
||||
- pull_3.actions | selectattr('status', 'eq', 'Creating') | length == 0
|
||||
- pull_3.actions | selectattr('status', 'eq', 'Recreating') | length == 0
|
||||
- pull_4_check is changed
|
||||
- pull_4_check.actions | selectattr('status', 'eq', 'Pulling') | first
|
||||
- pull_4 is not changed
|
||||
- pull_4.actions | selectattr('status', 'eq', 'Pulling') | first
|
||||
|
||||
- when: docker_compose_version is version('2.22.0', '<')
|
||||
block:
|
||||
@ -171,17 +184,9 @@
|
||||
that:
|
||||
- pull_1_check is changed
|
||||
- pull_1_check.actions | selectattr('status', 'eq', 'Pulling') | first
|
||||
- pull_1_check.actions | selectattr('status', 'eq', 'Creating') | length == 0
|
||||
- pull_1_check.actions | selectattr('status', 'eq', 'Recreating') | length == 0
|
||||
- pull_1 is changed
|
||||
- pull_1.actions | selectattr('status', 'eq', 'Pulling') | first
|
||||
- pull_1.actions | selectattr('status', 'eq', 'Creating') | length == 0
|
||||
- pull_1.actions | selectattr('status', 'eq', 'Recreating') | length == 0
|
||||
- pull_2_check is changed
|
||||
- pull_2_check.actions | selectattr('status', 'eq', 'Pulling') | first
|
||||
- pull_2_check.actions | selectattr('status', 'eq', 'Creating') | length == 0
|
||||
- pull_2_check.actions | selectattr('status', 'eq', 'Recreating') | length == 0
|
||||
- pull_2 is changed
|
||||
- pull_2 is not changed
|
||||
- pull_2.actions | selectattr('status', 'eq', 'Pulling') | first
|
||||
- pull_2.actions | selectattr('status', 'eq', 'Creating') | length == 0
|
||||
- pull_2.actions | selectattr('status', 'eq', 'Recreating') | length == 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user