From e2e22cae6e8fb9fcdb23fc4e65f787706754b92d Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Fri, 6 May 2022 14:47:43 -0500 Subject: [PATCH] Unify testing builds Unify Ansible testing builds into a single job Add a few basic "unit test" Ansible builds Update dependencies --- .github/workflows/test.yml | 56 ++++++++++++++----- ansible/molecule.yml | 14 +---- ansible/requirements.yml | 3 +- .../roles/init/molecule/shared/playbook.yml | 3 + .../roles/init/molecule/ubuntu16/molecule.yml | 8 +++ .../roles/init/molecule/ubuntu16/verify.yml | 11 ++++ .../roles/init/molecule/ubuntu18/molecule.yml | 8 +++ .../roles/init/molecule/ubuntu18/verify.yml | 11 ++++ ansible/roles/init/vars/Ubuntu.yml | 4 +- 9 files changed, 89 insertions(+), 29 deletions(-) create mode 100644 ansible/roles/init/molecule/shared/playbook.yml create mode 100644 ansible/roles/init/molecule/ubuntu16/molecule.yml create mode 100644 ansible/roles/init/molecule/ubuntu16/verify.yml create mode 100644 ansible/roles/init/molecule/ubuntu18/molecule.yml create mode 100644 ansible/roles/init/molecule/ubuntu18/verify.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ae808d5..bdb9946 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,8 +29,7 @@ jobs: name: Collect all Ansible-related jobs runs-on: ubuntu-latest outputs: - scenarios: ${{ steps.collection.outputs.tox-envs }} - vagrant: ${{ steps.vagrant.outputs.tox-envs }} + all: ${{ steps.zipped.outputs.scenarios }} steps: - uses: actions/checkout@v3 with: @@ -50,23 +49,50 @@ jobs: uses: greg-hellings/tox-list@v1 with: tox-args: --ansible-driver vagrant + - id: zipped + name: Zip arrays together + shell: python + run: | + import json + ubuntu = json.loads('${{ steps.collection.outputs.tox-envs }}') + macos = json.loads('${{ steps.vagrant.outputs.tox-envs }}') + ub_zip = [{'os': 'ubuntu-latest', 'scenario': u} for u in ubuntu] + mac_zip = [{'os': 'macos-10.15', 'scenario': m} for m in macos] + print("::set-output name=scenarios::" + json.dumps(ub_zip + mac_zip)) lint: name: Lint Ansible code - uses: devroles/meta_test/.github/workflows/lint.yml@master - - vagrant_build: - name: Ansible tests on VMs - needs: - - collect - uses: devroles/meta_test/.github/workflows/vagrant_build.yml@master - with: - scenarios: "${{ needs.collect.outputs.vagrant }}" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install Python + uses: actions/setup-python@v2 + - name: Install dependencies + run: |- + set -ex + python -m pip install --upgrade tox ansible + ansible-galaxy collection install -r ansible/requirements.yml + - name: Run lint + run: tox -e lint_all build: - name: Ansible tests on containers + name: Ansible tests on roles + runs-on: ${{ matrix.scenarios.os }} needs: - collect - uses: devroles/meta_test/.github/workflows/container_build.yml@master - with: - scenarios: "${{ needs.collect.outputs.scenarios }}" + strategy: + fail-fast: false + matrix: + scenarios: "${{ fromJson(needs.collect.outputs.all) }}" + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install Python + uses: actions/setup-python@v2 + - name: Install dependencies + run: python -m pip install --upgrade tox + - name: Run scenario + run: tox -e "${{ matrix.scenarios.scenario }}" diff --git a/ansible/molecule.yml b/ansible/molecule.yml index 76a6e7c..2b02ef2 100644 --- a/ansible/molecule.yml +++ b/ansible/molecule.yml @@ -1,8 +1,8 @@ dependency: name: galaxy options: - role-file: ../../requirements.yml # relative to the role dir - requirements-file: ../../requirements.yml + role-file: ../requirements.yml # relative to the role dir + requirements-file: ../requirements.yml provisioner: name: ansible playbooks: # These paths are relative to scenario dir @@ -15,14 +15,6 @@ provisioner: force_color: true remote_tmp: /tmp/${USER}/ansible verifier: - name: testinfra - options: - # Add a -v so you see the individual test names, - # particularly useful with parameterized tests - v: true - junit-xml: junit.xml - # Using the shared directory is useful for sharing tests across scenarios, - # but is not a requirement. For scenario specific tests, add the appropriate - # file path to the test or test directory below + name: ansible additional_files_or_dirs: - ../../shared/tests # relative to the scenario tests dir diff --git a/ansible/requirements.yml b/ansible/requirements.yml index e78bdcc..219cac7 100644 --- a/ansible/requirements.yml +++ b/ansible/requirements.yml @@ -1,2 +1,3 @@ collections: - - devroles.system + - name: devroles.system + version: "3.0.0" diff --git a/ansible/roles/init/molecule/shared/playbook.yml b/ansible/roles/init/molecule/shared/playbook.yml new file mode 100644 index 0000000..e5f3991 --- /dev/null +++ b/ansible/roles/init/molecule/shared/playbook.yml @@ -0,0 +1,3 @@ +- hosts: all + roles: + - init diff --git a/ansible/roles/init/molecule/ubuntu16/molecule.yml b/ansible/roles/init/molecule/ubuntu16/molecule.yml new file mode 100644 index 0000000..173d92c --- /dev/null +++ b/ansible/roles/init/molecule/ubuntu16/molecule.yml @@ -0,0 +1,8 @@ +driver: + name: vagrant + provider: + name: libvirt +platforms: + - name: test-ubuntu16-init + image: ubuntu:16.04 + box: generic/ubuntu1604 diff --git a/ansible/roles/init/molecule/ubuntu16/verify.yml b/ansible/roles/init/molecule/ubuntu16/verify.yml new file mode 100644 index 0000000..7f8c4df --- /dev/null +++ b/ansible/roles/init/molecule/ubuntu16/verify.yml @@ -0,0 +1,11 @@ +- hosts: all + tasks: + - name: Read init file + ansible.builtin.slurp: + path: /etc/default/console-setup + register: __slurped + + - name: Validate desired string is present + assert: + that: >- + 'ACTIVE_CONSOLES="/dev/tty1"' in ( __slurped["content"] | b64decode ) diff --git a/ansible/roles/init/molecule/ubuntu18/molecule.yml b/ansible/roles/init/molecule/ubuntu18/molecule.yml new file mode 100644 index 0000000..c5ce1ff --- /dev/null +++ b/ansible/roles/init/molecule/ubuntu18/molecule.yml @@ -0,0 +1,8 @@ +driver: + name: vagrant + provider: + name: libvirt +platforms: + - name: test-ubuntu18-init + image: ubuntu:18.04 + box: generic/ubuntu1804 diff --git a/ansible/roles/init/molecule/ubuntu18/verify.yml b/ansible/roles/init/molecule/ubuntu18/verify.yml new file mode 100644 index 0000000..7f8c4df --- /dev/null +++ b/ansible/roles/init/molecule/ubuntu18/verify.yml @@ -0,0 +1,11 @@ +- hosts: all + tasks: + - name: Read init file + ansible.builtin.slurp: + path: /etc/default/console-setup + register: __slurped + + - name: Validate desired string is present + assert: + that: >- + 'ACTIVE_CONSOLES="/dev/tty1"' in ( __slurped["content"] | b64decode ) diff --git a/ansible/roles/init/vars/Ubuntu.yml b/ansible/roles/init/vars/Ubuntu.yml index be39d0f..fb5217a 100644 --- a/ansible/roles/init/vars/Ubuntu.yml +++ b/ansible/roles/init/vars/Ubuntu.yml @@ -1,3 +1,3 @@ init_file: /etc/default/console-setup -init_regexp: '^(ACTIVE_CONSOLES="/dev/tty).*' -init_replace: \g<1>1 +init_regexp: '^(ACTIVE_CONSOLES="/dev/tty).*"' +init_replace: \g<1>1"