Skip to content

Commit

Permalink
Fix idempotency when containers have a common network (#279)
Browse files Browse the repository at this point in the history
Fix #252
  • Loading branch information
sshnaidm committed Aug 16, 2021
1 parent 8ac0752 commit afe55dd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
5 changes: 5 additions & 0 deletions plugins/module_utils/podman/podman_container_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,11 @@ def diffparam_network(self):
net_mode_before = net_mode_before.replace('bridge', 'default')
net_mode_before = net_mode_before.replace('slirp4netns', 'default')
return self._diff_update_and_compare('network', net_mode_before, net_mode_after)
# If container is attached to network of a different container
if "container" in net_mode_before:
for netw in after:
if "container" in netw:
before = after = netw
before, after = sorted(list(set(before))), sorted(list(set(after)))
return self._diff_update_and_compare('network', before, after)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
- name: Test podman rootful container with networks
block:

- name: Remove container rootlessnet2
containers.podman.podman_container:
name: rootlessnet2
state: absent

- name: Remove container rootlessnet
containers.podman.podman_container:
name: rootlessnet
Expand Down Expand Up @@ -166,9 +171,41 @@
that:
- info10 is not changed

- name: Run container network attached to first one
containers.podman.podman_container:
name: rootlessnet2
image: "{{ idem_image }}"
command: 1h
state: started
network: 'container:rootlessnet'
register: info11

- name: Check info container network attached to first one
assert:
that:
- info11 is changed

- name: Run container network attached to first one - again
containers.podman.podman_container:
name: rootlessnet2
image: "{{ idem_image }}"
command: 1h
state: started
network: 'container:rootlessnet'
register: info12

- name: Check info container network attached to first one - again
assert:
that:
- info12 is not changed
always:

- name: Delete all pods leftovers from tests
- name: Delete all containers leftovers from tests
containers.podman.podman_container:
name: rootlessnet2
state: absent

- name: Delete all containers leftovers from tests 2
containers.podman.podman_container:
name: rootlessnet
state: absent

0 comments on commit afe55dd

Please sign in to comment.