Skip to content

Commit

Permalink
Fix idempotency when containers have a common network
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 c96565b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 31 deletions.
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
Expand Up @@ -12,7 +12,7 @@
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
state: started
command: 1h
register: test1

Expand All @@ -23,7 +23,7 @@
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
state: started
command: 1h
ports:
- "4444:4444/tcp"
Expand All @@ -45,7 +45,7 @@
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
state: started
command: 1h
ports:
- "4444:4444/tcp"
Expand All @@ -67,7 +67,7 @@
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
state: started
publish_all: true
command: 1h
register: test4
Expand All @@ -79,7 +79,7 @@
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
state: started
publish_all: true
command: 1h
register: test5
Expand All @@ -91,7 +91,7 @@
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
state: started
command: 1h
register: test6

Expand All @@ -102,7 +102,7 @@
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
state: started
ports:
- 10000:8080
command: 1h
Expand All @@ -115,7 +115,7 @@
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
state: started
ports:
- 10001:8080
command: 1h
Expand All @@ -128,7 +128,7 @@
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
state: started
ports:
- 10001:8080/tcp
command: 1h
Expand All @@ -141,7 +141,7 @@
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
state: started
ports:
- 10001:8080/tcp
publish_all: false
Expand All @@ -155,7 +155,7 @@
- containers.podman.podman_container:
image: "{{ idem_image }}"
name: idempotency
state: present
state: started
command: 1h
register: test9b

Expand All @@ -170,13 +170,13 @@
- containers.podman.podman_container:
image: alpine
name: idempotency1
state: present
state: started
command: sleep 1h

- containers.podman.podman_container:
image: alpine
name: idempotency1
state: present
state: started
command: sleep 1h
register: test10

Expand All @@ -187,7 +187,7 @@
- containers.podman.podman_container:
image: alpine
name: idempotency1
state: present
state: started
publish_all: false
command: sleep 1h
register: test11
Expand All @@ -199,7 +199,7 @@
- containers.podman.podman_container:
image: alpine
name: idempotency1
state: present
state: started
publish_all: true
command: sleep 1h
register: test11a
Expand All @@ -211,7 +211,7 @@
- containers.podman.podman_container:
image: alpine
name: idempotency1
state: present
state: started
ports:
- 10000:8080
command: sleep 1h
Expand All @@ -224,7 +224,7 @@
- containers.podman.podman_container:
image: alpine
name: idempotency1
state: present
state: started
command: sleep 1h
register: test13

Expand All @@ -235,7 +235,7 @@
- containers.podman.podman_container:
image: alpine
name: idempotency1
state: present
state: started
command: sleep 1h
register: test14

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

- name: Remove container rootlessnet
containers.podman.podman_container:
name: rootlessnet
name: "{{ item }}"
state: absent
loop:
- rootlessnet
- rootlessnet2

- name: Run container with no specified networks
containers.podman.podman_container:
Expand All @@ -18,7 +21,7 @@
name: rootlessnet
image: "{{ idem_image }}"
command: 1h
state: present
state: started
register: info

- name: Check info for no specified networks
Expand All @@ -31,7 +34,7 @@
name: rootlessnet
image: "{{ idem_image }}"
command: 1h
state: present
state: started
network: host
register: info1

Expand All @@ -45,7 +48,7 @@
name: rootlessnet
image: "{{ idem_image }}"
command: 1h
state: present
state: started
network: host
register: info2

Expand All @@ -59,7 +62,7 @@
name: rootlessnet
image: "{{ idem_image }}"
command: 1h
state: present
state: started
network: none
register: info3

Expand All @@ -73,7 +76,7 @@
name: rootlessnet
image: "{{ idem_image }}"
command: 1h
state: present
state: started
network: none
register: info4

Expand All @@ -87,7 +90,7 @@
name: rootlessnet
image: "{{ idem_image }}"
command: 1h
state: present
state: started
register: info5

- name: Check info with default network mode
Expand All @@ -100,7 +103,7 @@
name: rootlessnet
image: "{{ idem_image }}"
command: 1h
state: present
state: started
network:
- slirp4netns:allow_host_loopback=true,cidr=10.0.3.0/24
register: info6
Expand All @@ -115,7 +118,7 @@
name: rootlessnet
image: "{{ idem_image }}"
command: 1h
state: present
state: started
network:
- slirp4netns:allow_host_loopback=true,cidr=10.0.3.0/24
register: info7
Expand All @@ -130,7 +133,7 @@
name: rootlessnet
image: "{{ idem_image }}"
command: 1h
state: present
state: started
network:
- slirp4netns:allow_host_loopback=true,cidr=10.0.4.0/24
register: info8
Expand All @@ -145,7 +148,7 @@
name: rootlessnet
image: "{{ idem_image }}"
command: 1h
state: present
state: started
register: info9

- name: Check info without options
Expand All @@ -158,17 +161,50 @@
name: rootlessnet
image: "{{ idem_image }}"
command: 1h
state: present
state: started
register: info10

- name: Check info without options - again
assert:
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
containers.podman.podman_container:
name: rootlessnet
name: "{{ item }}"
state: absent
loop:
- rootlessnet
- rootlessnet2

0 comments on commit c96565b

Please sign in to comment.