Browse Source

Merge "Update for a podman_container from collection"

changes/08/761908/11
Zuul 4 months ago
committed by Gerrit Code Review
parent
commit
f1e03a316a
4 changed files with 1549 additions and 1332 deletions
  1. +28
    -0
      tripleo_ansible/ansible_plugins/module_utils/podman/common.py
  2. +1452
    -0
      tripleo_ansible/ansible_plugins/module_utils/podman/podman_container_lib.py
  3. +48
    -1299
      tripleo_ansible/ansible_plugins/modules/podman_container.py
  4. +21
    -33
      tripleo_ansible/ansible_plugins/tests/molecule/podman_container/converge.yml

+ 28
- 0
tripleo_ansible/ansible_plugins/module_utils/podman/common.py View File

@ -0,0 +1,28 @@
#!/usr/bin/python
# Copyright (c) 2020 Red Hat
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
def run_podman_command(module, executable='podman', args=None, expected_rc=0, ignore_errors=False):
if not isinstance(executable, list):
command = [executable]
if args is not None:
command.extend(args)
rc, out, err = module.run_command(command)
if not ignore_errors and rc != expected_rc:
module.fail_json(
msg='Failed to run {command} {args}: {err}'.format(
command=command, args=args, err=err))
return rc, out, err
def lower_keys(x):
if isinstance(x, list):
return [lower_keys(v) for v in x]
elif isinstance(x, dict):
return dict((k.lower(), lower_keys(v)) for k, v in x.items())
else:
return x

+ 1452
- 0
tripleo_ansible/ansible_plugins/module_utils/podman/podman_container_lib.py
File diff suppressed because it is too large
View File


+ 48
- 1299
tripleo_ansible/ansible_plugins/modules/podman_container.py
File diff suppressed because it is too large
View File


+ 21
- 33
tripleo_ansible/ansible_plugins/tests/molecule/podman_container/converge.yml View File

@ -10,7 +10,7 @@
name: "{{ item }}"
state: absent
loop:
- "alpine:3.7"
- "ubi-minimal"
- "container"
- "container2"
@ -48,13 +48,13 @@
- name: Ensure image doesn't exist
podman_image:
name: alpine:3.7
name: registry.access.redhat.com/ubi8/ubi-minimal
state: absent
- name: Check pulling image
podman_container:
name: container
image: alpine:3.7
image: registry.access.redhat.com/ubi8/ubi-minimal
state: present
command: sleep 1d
register: image
@ -62,7 +62,7 @@
- name: Check using already pulled image
podman_container:
name: container2
image: alpine:3.7
image: registry.access.redhat.com/ubi8/ubi-minimal
state: present
command: sleep 1d
register: image2
@ -73,12 +73,12 @@
- image is changed
- image.container is defined
- image.container['State']['Running']
- "'pulled image alpine:3.7' in image.actions"
- "'pulled image registry.access.redhat.com/ubi8/ubi-minimal' in image.actions"
- "'started container' in image.actions"
- image2 is changed
- image2.container is defined
- image2.container['State']['Running']
- "'pulled image alpine:3.7' not in image2.actions"
- "'pulled image registry.access.redhat.com/ubi8/ubi-minimal' not in image2.actions"
- "'started container2' in image2.actions"
fail_msg: Pulling image test failed!
success_msg: Pulling image test passed!
@ -102,7 +102,7 @@
- name: Force container recreate
podman_container:
name: container
image: alpine
image: registry.access.redhat.com/ubi8/ubi-minimal
state: present
command: sleep 1d
recreate: true
@ -173,7 +173,7 @@
- name: Create container, but don't run
podman_container:
name: container
image: alpine:3.7
image: registry.access.redhat.com/ubi8/ubi-minimal
state: stopped
command: sleep 1d
register: created
@ -197,7 +197,7 @@
- name: Start container that was deleted
podman_container:
name: container
image: alpine:3.7
image: registry.access.redhat.com/ubi8/ubi-minimal
state: started
command: sleep 1d
register: started
@ -208,7 +208,7 @@
- started is changed
- started.container is defined
- started.container['State']['Running']
- "'pulled image alpine:3.7' not in started.actions"
- "'pulled image registry.access.redhat.com/ubi8/ubi-minimal' not in started.actions"
- name: Delete started container
podman_container:
@ -239,7 +239,7 @@
- name: Recreate container with parameters
podman_container:
name: container
image: docker.io/alpine:3.7
image: registry.access.redhat.com/ubi8/ubi-minimal
state: started
command: sleep 1d
recreate: true
@ -306,7 +306,7 @@
- "'TEST=1' in test.container['Config']['Env']"
- "'BOOL=False' in test.container['Config']['Env']"
# test labels
- test.container['Config']['Labels'] | length == 2
- test.container['Config']['Labels'] | length >= 2
- test.container['Config']['Labels']['somelabel'] == "labelvalue"
- test.container['Config']['Labels']['otheralbe'] == "othervalue"
# test mounts
@ -326,14 +326,14 @@
- name: Check basic idempotency of running container
podman_container:
name: testidem
image: docker.io/alpine
image: registry.access.redhat.com/ubi8/ubi-minimal
state: present
command: sleep 20m
- name: Check basic idempotency of running container - run it again
podman_container:
name: testidem
image: alpine:latest
image: ubi-minimal:latest
state: present
command: sleep 20m
register: idem
@ -346,7 +346,7 @@
- name: Run changed container (with tty enabled)
podman_container:
name: testidem
image: alpine
image: ubi-minimal
state: present
command: sleep 20m
tty: true
@ -360,7 +360,7 @@
- name: Run changed container without specifying an option, use defaults
podman_container:
name: testidem
image: alpine
image: ubi-minimal
state: present
command: sleep 20m
register: idem2
@ -384,7 +384,7 @@
- name: Check basic idempotency of pod container
podman_container:
name: testidem-pod
image: docker.io/alpine
image: registry.access.redhat.com/ubi8/ubi-minimal
state: present
command: sleep 20m
pod: "new:testidempod"
@ -392,7 +392,7 @@
- name: Check basic idempotency of pod container - run it again
podman_container:
name: testidem-pod
image: alpine:latest
image: ubi-minimal:latest
state: present
command: sleep 20m
pod: testidempod
@ -406,7 +406,7 @@
- name: Run changed pod container (with tty enabled)
podman_container:
name: testidem-pod
image: alpine
image: ubi-minimal
state: present
command: sleep 20m
tty: true
@ -423,30 +423,18 @@
name: testidem-pod
state: absent
- name: Run three containers at once
podman_containers:
containers:
- name: alpine
image: alpine
command: sleep 1d
- name: web
image: nginx
- name: test
image: python:3-alpine
command: python -V
always:
- name: Delete all container leftovers from tests
podman_container:
name: "{{ item }}"
state: absent
loop:
- "alpine:3.7"
- "container"
- "container2"
- "alpine"
- "ubi-minimal"
- "web"
- "test"
- "testidem"
- name: Remove pod
shell: podman pod rm -f testidempod

Loading…
Cancel
Save