From d27bbba9511d4cc4d311fd7bcef847fe02d8dd38 Mon Sep 17 00:00:00 2001 From: Sergey <6213510+sshnaidm@users.noreply.github.com> Date: Mon, 28 Nov 2022 19:49:27 -0500 Subject: [PATCH] DNM: add CI for module testing Signed-off-by: Sagi Shnaidman --- .github/workflows/podman_lovely_module.yml | 99 +++++++++++++++++++ .../containers/podman_lovely_module.yml | 8 ++ .../podman_lovely_module/tasks/main.yml | 23 +++++ 3 files changed, 130 insertions(+) create mode 100644 .github/workflows/podman_lovely_module.yml create mode 100644 ci/playbooks/containers/podman_lovely_module.yml create mode 100644 tests/integration/targets/podman_lovely_module/tasks/main.yml diff --git a/.github/workflows/podman_lovely_module.yml b/.github/workflows/podman_lovely_module.yml new file mode 100644 index 00000000..71ad21c4 --- /dev/null +++ b/.github/workflows/podman_lovely_module.yml @@ -0,0 +1,99 @@ +name: Podman lovely module + +on: + push: + paths: + - '.github/workflows/podman_lovely_module.yml' + - 'ci/*.yml' + - 'ci/run_containers_tests.sh' + - 'ci/playbooks/containers/podman_lovely_module.yml' + - 'plugins/modules/podman_lovely_module.py' + - 'tests/integration/targets/podman_lovely_module/**' + branches: + - master + pull_request: + paths: + - '.github/workflows/podman_lovely_module.yml' + - 'ci/*.yml' + - 'ci/run_containers_tests.sh' + - 'ci/playbooks/containers/podman_lovely_module.yml' + - 'plugins/modules/podman_lovely_module.py' + - 'tests/integration/targets/podman_lovely_module/**' + schedule: + - cron: 4 0 * * * # Run daily at 0:03 UTC + +jobs: + + test_podman_lovely_module: + name: Podman lovely module ${{ matrix.ansible-version }}-${{ matrix.os || 'ubuntu-22.04' }} + runs-on: ${{ matrix.os || 'ubuntu-22.04' }} + defaults: + run: + shell: bash + strategy: + fail-fast: false + matrix: + ansible-version: + - ansible<2.10 + # - git+https://github.com/ansible/ansible.git@stable-2.11 + - git+https://github.com/ansible/ansible.git@devel + os: + - ubuntu-22.04 + python-version: + - 3.9 + + steps: + + - name: Check out repository + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Upgrade pip and display Python and PIP versions + run: | + sudo apt-get update + sudo apt-get install -y python*-wheel python*-yaml + python -m pip install --upgrade pip + python -V + pip --version + - name: Set up pip cache + uses: actions/cache@v3 + 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: python3 -m pip install --user --force-reinstall --upgrade '${{ 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 + - name: Run collection tests for Podman lovely module + run: | + export PATH=~/.local/bin:$PATH + echo "Run ansible version" + command -v ansible + ansible --version + export ANSIBLE_CONFIG=$(pwd)/ci/ansible-dev.cfg + if [[ '${{ 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_lovely_module ./ci/run_containers_tests.sh + shell: bash diff --git a/ci/playbooks/containers/podman_lovely_module.yml b/ci/playbooks/containers/podman_lovely_module.yml new file mode 100644 index 00000000..7a8e7f6e --- /dev/null +++ b/ci/playbooks/containers/podman_lovely_module.yml @@ -0,0 +1,8 @@ +--- +- hosts: all + gather_facts: true + tasks: + - include_role: + name: podman_lovely_module + vars: + ansible_python_interpreter: "{{ _ansible_python_interpreter }}" diff --git a/tests/integration/targets/podman_lovely_module/tasks/main.yml b/tests/integration/targets/podman_lovely_module/tasks/main.yml new file mode 100644 index 00000000..50042ec5 --- /dev/null +++ b/tests/integration/targets/podman_lovely_module/tasks/main.yml @@ -0,0 +1,23 @@ +- name: Starting test something + containers.podman.podman_container: + name: blabla + image: alpine + +- name: Start using the tested module + containers.podman.podman_lovely_module: + name: blabla + register: info1 + +- name: Check that all results as should be + assert: + that: + - info1 is succeeded + - info1.my_data == 'test' + +# .................. + + +- name: Remove all test leftovers + containers.podman.podman_container: + name: blabla + state: absent