Skip to content

Commit

Permalink
Fix idempotency for empty values (#790)
Browse files Browse the repository at this point in the history
Fix #788
Signed-off-by: Sagi Shnaidman <[email protected]>
  • Loading branch information
sshnaidm authored Jun 20, 2024
1 parent f9aa887 commit 24c842f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions plugins/module_utils/podman/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,15 @@ def diff_generic(params, info_config, module_arg, cmd_arg, boolean_type=False):
after = ",".join(sorted([str(i).lower() for i in after]))
if before:
before = ",".join(sorted([str(i).lower() for i in before]))
else:
before = ''
elif isinstance(after, dict):
after = ",".join(sorted(
[str(k).lower() + "=" + str(v).lower() for k, v in after.items() if v is not None]))
if before:
before = ",".join(sorted([j.lower() for j in before]))
else:
before = ''
elif isinstance(after, bool):
after = str(after).capitalize()
if before is not None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@
assert:
that: test1 is not changed

- name: Run container with empty vars for list and dict
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
image: "{{ idem_image }}"
name: idempotency
state: present
env: {}
publish: []
command: 1h
register: test_to_empty

- name: Run container with empty vars for list and dict - again
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
image: "{{ idem_image }}"
name: idempotency
state: present
env: {}
publish: []
command: 1h
register: test_empty

- name: Run container again w/o empty vars
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
image: "{{ idem_image }}"
name: idempotency
state: present
command: 1h
register: test_from_empty

- name: Check info when running container again
assert:
that:
- test_to_empty is not changed
- test_empty is not changed
- test_from_empty is not changed

- name: Run container with environment vars
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
Expand Down

0 comments on commit 24c842f

Please sign in to comment.