Skip to content

Commit

Permalink
Improve idempotency for devices mount of rootless podman (#487)
Browse files Browse the repository at this point in the history

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
  • Loading branch information
sshnaidm committed Sep 28, 2022
1 parent 5f74d5b commit bf67c7e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
9 changes: 9 additions & 0 deletions plugins/module_utils/podman/podman_container_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,16 @@ def diffparam_cpuset_mems(self):
def diffparam_device(self):
before = [":".join([i['pathonhost'], i['pathincontainer']])
for i in self.info['hostconfig']['devices']]
if not before and 'createcommand' in self.info['config']:
cr_com = self.info['config']['createcommand']
if '--device' in cr_com:
before = [cr_com[k + 1].lower()
for k, i in enumerate(cr_com) if i == '--device']
before = [":".join((i, i))
if len(i.split(":")) == 1 else i for i in before]
after = [":".join(i.split(":")[:2]) for i in self.params['device']]
after = [":".join((i, i))
if len(i.split(":")) == 1 else i for i in after]
before, after = sorted(list(set(before))), sorted(list(set(after)))
return self._diff_update_and_compare('devices', before, after)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,68 @@
tag: sometag
command: 1h

- name: Run container with mounted /dev/fuse
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
image: "{{ idem_image }}"
name: idempotency
state: started
command: 1h
device:
- /dev/fuse
register: test15

- name: Run container with mounted /dev/fuse again
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
image: "{{ idem_image }}"
name: idempotency
state: started
command: 1h
device:
- /dev/fuse
register: test16

- name: Run container with mounted /dev/fuse:/dev/fuse
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
image: "{{ idem_image }}"
name: idempotency
state: started
command: 1h
device:
- /dev/fuse:/dev/fuse
register: test17

- name: Run container with mounted /dev/fuse third time
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
image: "{{ idem_image }}"
name: idempotency
state: started
command: 1h
device:
- /dev/fuse
register: test18

- name: Run container without mounted device
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
image: "{{ idem_image }}"
name: idempotency
state: started
command: 1h
register: test19

- name: Check info with mounted devices
assert:
that:
- test15 is changed
- test16 is not changed
- test17 is not changed
- test18 is not changed
- test19 is changed

- name: Remove test container
containers.podman.podman_container:
executable: "{{ test_executable | default('podman') }}"
Expand Down

0 comments on commit bf67c7e

Please sign in to comment.