Browse Source

Improve idempotency of podman_container

Make image comparing more readable
If 'command' is not set, don't compare it with current,
assume it's empty.

Change-Id: I935c617b242fb955ed08ed492bbd09e7f3f4fd4c
(cherry picked from commit fe6d3d4721)
changes/54/706354/1
Sagi Shnaidman Emilien Macchi 1 month ago
parent
commit
b750574710
2 changed files with 23 additions and 17 deletions
  1. +21
    -15
      tripleo_ansible/ansible_plugins/modules/podman_container.py
  2. +2
    -2
      tripleo_ansible/ansible_plugins/tests/molecule/podman_container/playbook.yml

+ 21
- 15
tripleo_ansible/ansible_plugins/modules/podman_container.py View File

@@ -1397,13 +1397,16 @@ class PodmanContainerDiff:
return self._diff_update_and_compare('cidfile', before, after)

def diffparam_command(self):
before = self.info['config']['cmd']
after = self.params['command']
if isinstance(after, str):
after = [i.lower() for i in after.split()]
elif isinstance(after, list):
after = [i.lower() for i in after]
return self._diff_update_and_compare('command', before, after)
# TODO(sshnaidm): to inspect image to get the default command
if self.module.params['command'] is not None:
before = self.info['config']['cmd']
after = self.params['command']
if isinstance(after, str):
after = [i.lower() for i in after.split()]
elif isinstance(after, list):
after = [i.lower() for i in after]
return self._diff_update_and_compare('command', before, after)
return False

def diffparam_conmon_pidfile(self):
before = self.info['conmonpidfile']
@@ -1515,14 +1518,17 @@ class PodmanContainerDiff:
return self._diff_update_and_compare('hostname', before, after)

def diffparam_image(self):
before = self.info['config']['image'].replace(
"docker.io/library/", "").replace(
"docker.io/", "").replace(
":latest", "")
after = self.params['image'].replace(
"docker.io/library/", "").replace(
"docker.io/", "").replace(
":latest", "")
# TODO(sshnaidm): for strict image compare use SHAs
before = self.info['config']['image']
after = self.params['image']
strip_from_name = [
"docker.io/library/",
"docker.io/",
":latest",
]
for repl in strip_from_name:
before = before.replace(repl, "")
after = after.replace(repl, "")
return self._diff_update_and_compare('image', before, after)

def diffparam_ipc(self):


+ 2
- 2
tripleo_ansible/ansible_plugins/tests/molecule/podman_container/playbook.yml View File

@@ -327,14 +327,14 @@
- name: Check basic idempotency of running container
podman_container:
name: testidem
image: alpine
image: docker.io/alpine
state: present
command: sleep 20m

- name: Check basic idempotency of running container - run it again
podman_container:
name: testidem
image: alpine
image: alpine:latest
state: present
command: sleep 20m
register: idem


Loading…
Cancel
Save