1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-03 23:01:48 +00:00

Set up testing for podman connection

This commit is contained in:
Sagi Shnaidman 2020-04-20 11:35:11 +03:00
parent 65b6f5b278
commit f79f36fd38
32 changed files with 563 additions and 109 deletions

4
ci/ansible-2.9.cfg Normal file
View file

@ -0,0 +1,4 @@
[defaults]
bin_ansible_callbacks = True
stdout_callback = debug
force_color = True

2
ci/ansible-dev.cfg Normal file
View file

@ -0,0 +1,2 @@
[defaults]
force_color = True

73
ci/playbooks/build.yml Normal file
View file

@ -0,0 +1,73 @@
- hosts: "{{ host|default('all') }}"
gather_facts: true
vars:
repo_url: https://github.com/containers/ansible-podman-collections.git
repo_dir: "/home/{{ ansible_user }}/ansible-podman-collections"
temp_collect: /tmp/collection
distro: "{{ ansible_distribution }}{{ ansible_distribution_major_version }}"
tasks:
- name: Set PR vars if defined
set_fact:
pr_branch: "pull/{{ pr }}/head"
pr_refspec: "refs/pull/{{ pr }}/head:refs/remotes/origin/pull/{{ pr }}/head"
when: pr is defined
- name: Clone collection
git:
dest: "{{ repo_dir }}"
repo: "{{ repo_url }}"
version: "{{ pr_branch|default('master') }}"
refspec: "{{ pr_refspec|default(omit) }}"
force: true
register: git_clone
ignore_errors: true
when: clone_repo|default(true)|bool
# https://github.com/ansible/ansible/issues/67972
- name: Update manually if need
command: git fetch -f -u origin {{ pr_branch }}:{{ pr_branch }}
args:
chdir: "{{ repo_dir }}"
when:
- git_clone is failed
- pr is defined
- name: Remove temporary collection dir
file:
path: "{{ temp_collect }}"
state: absent
- name: Create temporary collection dir
file:
path: "{{ temp_collect }}"
state: directory
- name: Build collection
shell: >-
{% if ansible_venv is defined %}source {{ ansible_venv }}/bin/activate;{% endif %}
ansible-galaxy collection build --output-path {{ temp_collect }} --force
args:
chdir: "{{ repo_dir }}"
- name: Find a path of collection file
find:
paths: "{{ temp_collect }}/"
patterns: "*tar.gz"
register: file_path
- name: Install collection
become: "{{ distro == 'CentOS7' }}"
shell: >-
{% if ansible_venv is defined %}source {{ ansible_venv }}/bin/activate;{% endif %}
ansible-galaxy collection install {{ file_path.files.0.path }} --force
args:
chdir: "{{ repo_dir }}"
- name: Install collection for root
become: true
shell: >-
{% if ansible_venv is defined %}source {{ ansible_venv }}/bin/activate;{% endif %}
ansible-galaxy collection install {{ file_path.files.0.path }} --force
args:
chdir: "{{ repo_dir }}"

View file

@ -0,0 +1,14 @@
---
- 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 %}
{{ repo_dir }}/ci/run_connection_test.sh

View file

@ -0,0 +1,19 @@
---
- hosts: "{{ host|default('all') }}"
connection: "{{ connection_type }}"
tasks:
- name: Copy file
copy:
src: /tmp/local_file
dest: ~/
- name: Copy file from container
fetch:
src: ~/local_file
dest: /tmp/remote_file
flat: true
- name: Compare test files
shell: diff -q /tmp/local_file /tmp/remote_file
delegate_to: localhost

View file

@ -0,0 +1,9 @@
---
- name: Install repo for ubuntu
become: true
shell: |
. /etc/os-release
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
curl -L https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key | apt-key add -
apt-get update
when: ansible_distribution|lower == "ubuntu"

18
ci/playbooks/local.yml Normal file
View file

@ -0,0 +1,18 @@
---
- include: pre.yml
vars:
host: localhost
ansible_venv: /tmp/ansible-test
ansible_venv_site_packages: true
clean_venv: true
- include: build.yml
vars:
host: localhost
repo_dir: "{{ source | default('/tmp/ansible-podman-collections-test') }}"
clone_repo: "{{ source is not defined }}"
- include: connection_test.yml
vars:
host: localhost
repo_dir: "{{ source | default('/tmp/ansible-podman-collections-test') }}"

87
ci/playbooks/pre.yml Normal file
View file

@ -0,0 +1,87 @@
---
- hosts: "{{ host|default('all') }}"
gather_facts: true
vars:
ansible_pip_version: '<2.10'
distro: "{{ ansible_distribution }}{{ ansible_distribution_major_version }}"
tasks:
- become: true
block:
- name: Install Python3 and pip
package:
name:
- python3
- python3-pip
when:
- distro != 'CentOS7'
- setup_python|default(true)|bool
- name: Install EPEL for CentOS 7
package:
name:
- epel-release
when:
- distro == 'CentOS7'
- setup_python|default(true)|bool
- name: Install Python and pip for CentOS 7
package:
name:
- python
- python-pip
when:
- distro == 'CentOS7'
- setup_python|default(true)|bool
- name: Upgrade pip
pip:
name: pip
extra_args: --upgrade
- name: Install virtualenv
pip:
name:
- virtualenv
when: ansible_venv is defined
- name: Remove virtualenv if need
file:
path: "{{ ansible_venv }}"
state: absent
when:
- clean_venv|default(false)|bool
- ansible_venv is defined
- name: Install ansible
pip:
name: ansible
version: "{{ ansible_pip_version }}"
extra_args: --upgrade
virtualenv: "{{ ansible_venv|default(omit) }}"
virtualenv_site_packages: "{{ ansible_venv_site_packages|default(omit) }}"
environment:
PATH: /usr/local/bin:{{ ansible_env.PATH }}
when:
- ansible_venv is defined
- name: Install repositories if need
include_tasks: install_repos.yml
- name: Install podman
package:
name:
- podman
- buildah
- git
- vim
- name: Get podman version
shell: |
podman version
buildah version
podman info --debug
buildah info --debug
conmon --version
runc --version

42
ci/run_connection_test.sh Executable file
View file

@ -0,0 +1,42 @@
#!/bin/bash
set -o pipefail
set -eux
CON_TYPE="${1:-podman}"
SUDO=${ROOT:+"sudo -E"}
ANSIBLECMD=$(command -v ansible-playbook)
echo "Testing $CON_TYPE connection ${ROOT:+'with root'}"
if [[ "$CON_TYPE" == "podman" ]]; then
${SUDO} podman ps | grep -q "${CON_TYPE}-container" || \
${SUDO} podman run -d --rm --name "${CON_TYPE}-container" python:3-alpine sleep 1d
elif [[ "$CON_TYPE" == "buildah" ]]; then
${SUDO} buildah from --name=buildah-container python:2
fi
pushd "tests/integration/targets/connection_${CON_TYPE}"
ANSIBLECMD=${ANSIBLECMD} SUDO="${SUDO}" ./runme.sh
popd
# Create a big file for uploading to container
[[ ! -f /tmp/local_file ]] && head -c 5M </dev/urandom >/tmp/local_file
exit_code=0
CMD="${SUDO:-} ${ANSIBLECMD:-ansible-playbook} \
-i tests/integration/targets/connection_${CON_TYPE}/test_connection.inventory \
-e connection_type=containers.podman.${CON_TYPE} \
ci/playbooks/connections/test.yml"
$CMD -vv || exit_code=$?
if [[ "$exit_code" != 0 ]]; then
$CMD -vvvvv
fi
# Clean up
if [[ "$CON_TYPE" == "podman" ]]; then
${SUDO} podman rm -f "${CON_TYPE}-container"
elif [[ "$CON_TYPE" == "buildah" ]]; then
${SUDO} buildah rm buildah-container
fi
${SUDO} rm -f /tmp/local_file