Skip to content

Commit 11f9ede

Browse files
authored
Fix idempoency issue with PID of container (#622)
Fix #573 Signed-off-by: Sagi Shnaidman <[email protected]>
1 parent 4812aea commit 11f9ede

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

plugins/module_utils/podman/podman_container_lib.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,8 +1136,19 @@ def diffparam_privileged(self):
11361136
return self._diff_update_and_compare('privileged', before, after)
11371137

11381138
def diffparam_pid(self):
1139+
def get_container_id_by_name(name):
1140+
rc, podman_inspect_info, err = self.module.run_command(
1141+
[self.module.params["executable"], "inspect", name, "-f", "{{.Id}}"])
1142+
if rc != 0:
1143+
return None
1144+
return podman_inspect_info.strip()
1145+
11391146
before = self.info['hostconfig']['pidmode']
11401147
after = self.params['pid']
1148+
if after is not None and "container:" in after and "container:" in before:
1149+
if after.split(":")[1] == before.split(":")[1]:
1150+
return self._diff_update_and_compare('pid', before, after)
1151+
after = "container:" + get_container_id_by_name(after.split(":")[1])
11411152
return self._diff_update_and_compare('pid', before, after)
11421153

11431154
# TODO(sshnaidm) Need to add port ranges support

tests/integration/targets/podman_container_idempotency/tasks/idem_all.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,63 @@
332332
assert:
333333
that: test25 is changed
334334

335+
- name: Run container for linking with PID
336+
containers.podman.podman_container:
337+
executable: "{{ test_executable | default('podman') }}"
338+
image: "{{ idem_image }}"
339+
name: idempotency
340+
state: present
341+
register: test26
342+
343+
- name: Check info with PID
344+
assert:
345+
that: test26 is not changed
346+
347+
- name: Run second container for linking with PID
348+
containers.podman.podman_container:
349+
executable: "{{ test_executable | default('podman') }}"
350+
image: "{{ idem_image }}"
351+
name: idempotency2
352+
state: present
353+
pid: "container:idempotency"
354+
register: test27
355+
356+
- name: Check info of second container with PID
357+
assert:
358+
that: test27 is changed
359+
360+
- name: Run second container for linking with PID
361+
containers.podman.podman_container:
362+
executable: "{{ test_executable | default('podman') }}"
363+
image: "{{ idem_image }}"
364+
name: idempotency2
365+
state: present
366+
pid: "container:idempotency"
367+
register: test28
368+
369+
- name: Check info of second container with PID again
370+
assert:
371+
that: test28 is not changed
372+
373+
- name: Run second container for linking with PID with container ID
374+
containers.podman.podman_container:
375+
executable: "{{ test_executable | default('podman') }}"
376+
image: "{{ idem_image }}"
377+
name: idempotency2
378+
state: present
379+
pid: "container:{{ test26.container.Id }}"
380+
register: test29
381+
382+
- name: Check info of second container with PID of container ID again
383+
assert:
384+
that: test29 is not changed
385+
386+
- name: Remove dependant test container
387+
containers.podman.podman_container:
388+
executable: "{{ test_executable | default('podman') }}"
389+
name: idempotency2
390+
state: absent
391+
335392
- name: Remove test container
336393
containers.podman.podman_container:
337394
executable: "{{ test_executable | default('podman') }}"

0 commit comments

Comments
 (0)