1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-04 07:11:49 +00:00

Add CI for podman_container

This commit is contained in:
Sagi Shnaidman 2020-05-10 16:24:21 +03:00 committed by Sergey
parent 6d0a24b52a
commit 277a3129f0
18 changed files with 215 additions and 66 deletions

View file

@ -3,8 +3,10 @@ name: Test connection plugins
on:
push:
paths:
- '.github/workflows/*'
- 'ci/**'
- '.github/workflows/connections_tests.yml'
- 'ci/*.yml'
- 'ci/playbooks/connections/**'
- 'ci/run_connection_test.sh'
- 'plugins/connection/**'
- 'tests/integration/targets/connection/**'
- 'tests/integration/targets/connection_*/**'
@ -12,8 +14,10 @@ on:
- master
pull_request:
paths:
- '.github/workflows/*'
- 'ci/**'
- '.github/workflows/connections_tests.yml'
- 'ci/*.yml'
- 'ci/playbooks/connections/**'
- 'ci/run_connection_test.sh'
- 'plugins/connection/**'
- 'tests/integration/targets/connection/**'
- 'tests/integration/targets/connection_*/**'

101
.github/workflows/podman_container.yml vendored Normal file
View file

@ -0,0 +1,101 @@
name: Podman container
on:
push:
paths:
- '.github/workflows/podman_container.yml'
- 'ci/*.yml'
- 'ci/containers/podman_container.yml'
- 'plugins/modules/podman_container.py'
- 'plugins/modules/podman_container_info.py'
- 'tests/integration/targets/podman_container/**'
branches:
- master
pull_request:
paths:
- '.github/workflows/podman_container.yml'
- 'ci/*.yml'
- 'ci/containers/podman_container.yml'
- 'plugins/modules/podman_container.py'
- 'plugins/modules/podman_container_info.py'
- 'tests/integration/targets/podman_container/**'
schedule:
- cron: 4 0 * * * # Run daily at 0:03 UTC
jobs:
test_podman_container:
name: Podman container ${{ matrix.ansible-version }}-${{ matrix.os.vm || 'ubuntu-latest' }}
runs-on: ${{ matrix.os.vm || 'ubuntu-latest' }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
ansible-version:
- ansible<2.10
- git+https://github.com/ansible/ansible.git@devel
os:
- vm: ubuntu-latest
python-version:
- 3.7
steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Upgrade pip and display Python and PIP versions
run: |
python -m pip install --upgrade pip
python -V
pip --version
- name: Set up pip cache
uses: actions/cache@v1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ github.ref }}-units-VMs
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install Ansible ${{ matrix.ansible-version }}
run: python -m pip install --user '${{ matrix.ansible-version }}'
- name: Build and install the collection tarball
run: |
rm -rf /tmp/just_new_collection
~/.local/bin/ansible-galaxy collection build --output-path /tmp/just_new_collection --force
~/.local/bin/ansible-galaxy collection install -vvv --force /tmp/just_new_collection/*.tar.gz
sudo ~/.local/bin/ansible-galaxy collection install -vvv --force /tmp/just_new_collection/*.tar.gz
- name: Run collection tests for connection
run: |
export PATH=~/.local/bin:$PATH
if [[ '${{ matrix.ansible-version }}' == 'git+https://github.com/ansible/ansible.git@devel' ]]; then
export ANSIBLE_CONFIG=$(pwd)/ci/ansible-dev.cfg
elif [[ '${{ matrix.ansible-version }}' == 'ansible<2.10' ]]; then
export ANSIBLE_CONFIG=$(pwd)/ci/ansible-2.9.cfg
fi
echo $ANSIBLE_CONFIG
command -v ansible-playbook
pip --version
python --version
ansible-playbook --version
ansible-playbook -vv ci/playbooks/pre.yml \
-e host=localhost \
-i localhost, \
-e ansible_connection=local \
-e setup_python=false
TEST2RUN=podman_container ./ci/run_containers_tests.sh
shell: bash

View file

@ -14,3 +14,4 @@
{{ repo_dir }}/ci/run_connection_test.sh
args:
chdir: "{{ repo_dir }}"
executable: /bin/bash

View file

@ -0,0 +1,6 @@
---
- hosts: all
gather_facts: true
tasks:
- include_role:
name: podman_container

View file

@ -0,0 +1,17 @@
---
- hosts: "{{ host|default('all') }}"
gather_facts: true
vars:
repo_dir: "/home/{{ ansible_user }}/ansible-podman-collections"
distro: "{{ ansible_distribution }}{{ ansible_distribution_major_version }}"
tasks:
- name: Run test script
become: "{{ distro == 'CentOS7' }}"
shell: >-
{% if ansible_venv is defined %}source {{ ansible_venv }}/bin/activate; {% endif %}
TEST2RUN={{ test }} {{ repo_dir }}/ci/run_containers_tests.sh
args:
chdir: "{{ repo_dir }}"
executable: /bin/bash

23
ci/run_containers_tests.sh Executable file
View file

@ -0,0 +1,23 @@
#!/bin/bash
set -o pipefail
set -ex
[[ -z "$TEST2RUN" || ! -f "ci/playbooks/containers/${TEST2RUN}.yml" ]] && {
echo "Please specify test to run, for example TEST2RUN=podman_container";
exit 1;
}
ANSIBLECMD=${ANSIBLECMD:-$(command -v ansible-playbook)}
echo "Testing ${TEST2RUN} module"
CURWD="$(readlink -f $(dirname ${BASH_SOURCE[0]}))"
exit_code=0
CMD="ANSIBLE_ROLES_PATH=${CURWD}/../tests/integration/targets \
${ANSIBLECMD:-ansible-playbook} \
-i localhost, -c local --diff \
ci/playbooks/containers/${TEST2RUN}.yml"
bash -c "$CMD -vv" || exit_code=$?
if [[ "$exit_code" != 0 ]]; then
bash -c "$CMD -vvvvv --diff"
fi

View file

@ -1,6 +1,6 @@
namespace: containers
name: podman
version: 0.2.0
version: 0.3.0
readme: README.md
authors: Podman
description: Podman container Ansible modules

View file

@ -1258,7 +1258,6 @@ class PodmanDefaults:
self.defaults = {
"blkio_weight": 0,
"cgroups": "default",
"cgroup_parent": "",
"cidfile": "",
"cpus": 0.0,
"cpu_shares": 0,
@ -1382,6 +1381,8 @@ class PodmanContainerDiff:
def diffparam_cgroup_parent(self):
before = self.info['hostconfig']['cgroupparent']
after = self.params['cgroup_parent']
if after is None:
after = before
return self._diff_update_and_compare('cgroup_parent', before, after)
def diffparam_cgroups(self):

View file

@ -1,4 +0,0 @@
shippable/posix/group2
skip/osx
skip/freebsd
destructive

View file

@ -1,2 +0,0 @@
dependencies:
- setup_podman

View file

@ -1,8 +1,7 @@
- name: Test podman_container
become: true
block:
- name: Delete all container leftovers from tests
podman_container:
containers.podman.podman_container:
name: "{{ item }}"
state: absent
loop:
@ -11,20 +10,20 @@
- "container2"
- name: Test no image with default action
podman_container:
containers.podman.podman_container:
name: container
ignore_errors: true
register: no_image
- name: Test no image with state 'started'
podman_container:
containers.podman.podman_container:
name: container
state: started
ignore_errors: true
register: no_image1
- name: Test no image with state 'present'
podman_container:
containers.podman.podman_container:
name: container
state: present
ignore_errors: true
@ -43,12 +42,12 @@
success_msg: No image test passed!
- name: Ensure image doesn't exist
podman_image:
containers.podman.podman_image:
name: alpine:3.7
state: absent
- name: Check pulling image
podman_container:
containers.podman.podman_container:
name: container
image: alpine:3.7
state: present
@ -56,7 +55,7 @@
register: image
- name: Check using already pulled image
podman_container:
containers.podman.podman_container:
name: container2
image: alpine:3.7
state: present
@ -80,7 +79,7 @@
success_msg: Pulling image test passed!
- name: Check failed image pull
podman_container:
containers.podman.podman_container:
name: container
image: ineverneverneverexist
state: present
@ -96,7 +95,7 @@
- name: Force container recreate
podman_container:
containers.podman.podman_container:
name: container
image: alpine
state: present
@ -115,13 +114,13 @@
success_msg: Force recreate test passed!
- name: Stop container
podman_container:
containers.podman.podman_container:
name: container
state: stopped
register: stopped
- name: Stop the same container again (idempotency)
podman_container:
containers.podman.podman_container:
name: container
state: stopped
register: stopped_again
@ -141,13 +140,13 @@
success_msg: Stopping container test passed!
- name: Delete stopped container
podman_container:
containers.podman.podman_container:
name: container
state: absent
register: deleted
- name: Delete again container (idempotency)
podman_container:
containers.podman.podman_container:
name: container
state: absent
register: deleted_again
@ -167,7 +166,7 @@
success_msg: Deleting stopped container test passed!
- name: Create container, but don't run
podman_container:
containers.podman.podman_container:
name: container
image: alpine:3.7
state: stopped
@ -186,12 +185,12 @@
success_msg: "Creating stopped container test passed!"
- name: Delete created container
podman_container:
containers.podman.podman_container:
name: container
state: absent
- name: Start container that was deleted
podman_container:
containers.podman.podman_container:
name: container
image: alpine:3.7
state: started
@ -207,13 +206,13 @@
- "'pulled image alpine:3.7' not in started.actions"
- name: Delete started container
podman_container:
containers.podman.podman_container:
name: container
state: absent
register: deleted
- name: Delete again container (idempotency)
podman_container:
containers.podman.podman_container:
name: container
state: absent
register: deleted_again
@ -233,7 +232,7 @@
success_msg: Deleting started container test passed!
- name: Recreate container with parameters
podman_container:
containers.podman.podman_container:
name: container
image: docker.io/alpine:3.7
state: started
@ -260,7 +259,6 @@
BAR: foo
TEST: 1
BOOL: false
group_add: "somegroup"
label:
somelabel: labelvalue
otheralbe: othervalue
@ -321,14 +319,14 @@
success_msg: Parameters container test passed!
- name: Check basic idempotency of running container
podman_container:
containers.podman.podman_container:
name: testidem
image: docker.io/alpine
state: present
command: sleep 20m
- name: Check basic idempotency of running container - run it again
podman_container:
containers.podman.podman_container:
name: testidem
image: alpine:latest
state: present
@ -341,7 +339,7 @@
- not idem.changed
- name: Run changed container (with tty enabled)
podman_container:
containers.podman.podman_container:
name: testidem
image: alpine
state: present
@ -355,7 +353,7 @@
- idem1 is changed
- name: Run changed container without specifying an option, use defaults
podman_container:
containers.podman.podman_container:
name: testidem
image: alpine
state: present
@ -368,7 +366,7 @@
- idem2 is changed
- name: Remove container
podman_container:
containers.podman.podman_container:
name: testidem
state: absent
register: remove
@ -380,7 +378,7 @@
always:
- name: Delete all container leftovers from tests
podman_container:
containers.podman.podman_container:
name: "{{ item }}"
state: absent
loop:

View file

@ -13,7 +13,7 @@
ignore_errors: true
- name: Get missing container info
podman_container_info:
containers.podman.podman_container_info:
name: "{{ container_name }}"
register: nonexist
@ -25,7 +25,7 @@
- nonexist.containers == []
- name: Get missing multiple container info
podman_container_info:
containers.podman.podman_container_info:
name:
- "{{ container_name }}"
- neverexist
@ -44,19 +44,19 @@
command: podman container run -d --name {{ container_name }} alpine sleep 15m
- name: Get existing container info
podman_container_info:
containers.podman.podman_container_info:
name: "{{ container_name }}"
register: existing_container
- name: Get mixed existing and non-existing container info
podman_container_info:
containers.podman.podman_container_info:
name:
- "{{ container_name }}"
- whatever
register: mixed_existing_container
- name: Get all containers info
podman_container_info:
containers.podman.podman_container_info:
register: all_containers
- name: Dump podman container inspect result

View file

@ -4,12 +4,12 @@
- ansible_facts.distribution == 'RedHat'
block:
- name: Pull image
podman_image:
containers.podman.podman_image:
name: quay.io/coreos/alpine-sh
register: pull1
- name: Pull image again
podman_image:
containers.podman.podman_image:
name: quay.io/coreos/alpine-sh
register: pull2
@ -25,13 +25,13 @@
- "'alpine-sh' in images.stdout"
- name: Remove image
podman_image:
containers.podman.podman_image:
name: quay.io/coreos/alpine-sh
state: absent
register: rmi1
- name: Remove image again
podman_image:
containers.podman.podman_image:
name: quay.io/coreos/alpine-sh
state: absent
register: rmi2
@ -48,13 +48,13 @@
- "'alpine-sh' not in images.stdout"
- name: Pull a specific version of an image
podman_image:
containers.podman.podman_image:
name: quay.io/coreos/etcd
tag: v3.3.11
register: specific_image1
- name: Pull a specific version of an image again
podman_image:
containers.podman.podman_image:
name: quay.io/coreos/etcd
tag: v3.3.11
register: specific_image2
@ -81,19 +81,19 @@
dest: /var/tmp/build/Dockerfile
- name: Build OCI image
podman_image:
containers.podman.podman_image:
name: testimage
path: /var/tmp/build
register: oci_build1
- name: Build OCI image again
podman_image:
containers.podman.podman_image:
name: testimage
path: /var/tmp/build
register: oci_build2
- name: Inspect build image
podman_image_info:
containers.podman.podman_image_info:
name: testimage
register: testimage_info
@ -105,7 +105,7 @@
- "'localhost/testimage:latest' in testimage_info.images[0]['RepoTags'][0]"
- name: Build Docker image
podman_image:
containers.podman.podman_image:
name: dockerimage
path: /var/tmp/build
build:
@ -113,7 +113,7 @@
register: docker_build1
- name: Build Docker image again
podman_image:
containers.podman.podman_image:
name: dockerimage
path: /var/tmp/build
build:
@ -121,7 +121,7 @@
register: docker_build2
- name: Inspect build image
podman_image_info:
containers.podman.podman_image_info:
name: dockerimage
register: dockerimage_info
@ -134,7 +134,7 @@
always:
- name: Cleanup images
podman_image:
containers.podman.podman_image:
name: "{{ item }}"
state: absent
loop:

View file

@ -7,14 +7,14 @@
command: podman pull quay.io/coreos/etcd
- name: Get info on all images
podman_image_info:
containers.podman.podman_image_info:
register: all_image_result
- name: Pull another image
command: podman pull quay.io/coreos/dnsmasq
- name: Get info on specific image
podman_image_info:
containers.podman.podman_image_info:
name: dnsmasq
register: named_image_result
@ -26,19 +26,19 @@
- "'dnsmasq' in named_image_result.images[0]['RepoTags'][0]"
- name: Get info on single image that does not exist
podman_image_info:
containers.podman.podman_image_info:
name: nope
register: single_nonexistant
- name: Get info on multiple images that do not exist
podman_image_info:
containers.podman.podman_image_info:
name:
- nope
- reallynope
register: multiple_nonexistant
- name: Get info with one image that does not exist
podman_image_info:
containers.podman.podman_image_info:
name:
- dnsmasq
- nope

View file

@ -17,7 +17,7 @@
ignore_errors: true
- name: Get missing network info
podman_network_info:
containers.podman.podman_network_info:
name: "{{ network_name }}"
register: nonexist
ignore_errors: true
@ -32,7 +32,7 @@
command: podman network create {{ network_name }}
- name: Get existing network info
podman_network_info:
containers.podman.podman_network_info:
name: "{{ network_name }}"
register: existing_network

View file

@ -16,7 +16,7 @@
ignore_errors: true
- name: Get missing volume info
podman_volume_info:
containers.podman.podman_volume_info:
name: "{{ volume_name }}"
register: nonexist
ignore_errors: true
@ -31,7 +31,7 @@
command: podman volume create {{ volume_name }}
- name: Get existing volume info
podman_volume_info:
containers.podman.podman_volume_info:
name: "{{ volume_name }}"
register: existing_volume

View file

@ -11,5 +11,7 @@ plugins/modules/podman_container.py validate-modules:parameter-list-no-elements
plugins/modules/podman_container.py import-3.7!skip
plugins/modules/podman_container.py import-2.7!skip
ci/run_connection_test.sh shebang!skip
ci/run_containers_tests.sh shellcheck!skip
ci/run_containers_tests.sh shebang!skip
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086

View file

@ -6,5 +6,7 @@ plugins/modules/podman_container.py validate-modules!skip
plugins/modules/podman_container.py import-3.7!skip
plugins/modules/podman_container.py import-2.7!skip
ci/run_connection_test.sh shebang!skip
ci/run_containers_tests.sh shellcheck!skip
ci/run_containers_tests.sh shebang!skip
tests/integration/targets/connection_buildah/runme.sh shellcheck:SC2086
tests/integration/targets/connection_podman/runme.sh shellcheck:SC2086