From 8448e1f18755e0520e30ecc84a5b14c3b6124adc Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Wed, 8 Jun 2022 13:56:47 -0500 Subject: [PATCH] Speed up Ansible tests Move Molecule Vagrant tests over to QEmu runners on Linux boxes "Dog-food" the Vagrant VMs Accelerate linting of Ansible code as well --- .github/actions/install_packer/action.yml | 10 +++-- .github/actions/install_virtualbox/action.yml | 9 ----- .github/workflows/build.yml | 2 +- .github/workflows/test.yml | 37 ++++++++++++++----- .../roles/init/molecule/ubuntu16/molecule.yml | 8 ---- .../roles/init/molecule/ubuntu16/verify.yml | 11 ------ .../roles/init/molecule/ubuntu18/molecule.yml | 5 ++- .../virtualbox/molecule/ubuntu18/molecule.yml | 5 +-- .../virtualbox/molecule/ubuntu20/molecule.yml | 5 +-- 9 files changed, 39 insertions(+), 53 deletions(-) delete mode 100644 .github/actions/install_virtualbox/action.yml delete mode 100644 ansible/roles/init/molecule/ubuntu16/molecule.yml delete mode 100644 ansible/roles/init/molecule/ubuntu16/verify.yml diff --git a/.github/actions/install_packer/action.yml b/.github/actions/install_packer/action.yml index 3664593..a5f7ff7 100644 --- a/.github/actions/install_packer/action.yml +++ b/.github/actions/install_packer/action.yml @@ -13,14 +13,15 @@ inputs: runs: using: composite steps: - - shell: bash + - name: Install Packer and deps in Linux + shell: bash if: runner.os == 'Linux' run: | set -exo pipefail # Install virtualbox sudo apt-get update # Install QEmu, etc - sudo apt-get install -y unzip python3-{virtualenv,yaml} cloud-utils xorriso qemu-system-{x86,ppc} + sudo apt-get install -y unzip python3-{virtualenv,yaml} cloud-utils xorriso qemu-system-{x86,ppc} vagrant # Install packer.io curl -O https://releases.hashicorp.com/packer/${{ inputs.version }}/packer_${{ inputs.version }}_linux_amd64.zip unzip -o packer_${{ inputs.version }}_linux_amd64.zip -d /usr/local/bin @@ -29,9 +30,10 @@ runs: curl -L -o pup.zip "https://github.com/ericchiang/pup/releases/download/${{ inputs.pup_version }}/pup_${{ inputs.pup_version }}_linux_amd64.zip" sudo unzip pup.zip -d /usr/local/bin sudo chmod +x /usr/local/bin/pup - - shell: bash + - name: Install Packer's deps in macOS + shell: bash if: runner.os == 'macOS' run: | set -exo pipefail - brew install pup dvdrtools xorriso coreutils gsed + brew install pup dvdrtools xorriso coreutils gsed virtualbox vagrant # Packer is already installed diff --git a/.github/actions/install_virtualbox/action.yml b/.github/actions/install_virtualbox/action.yml deleted file mode 100644 index 3d8b754..0000000 --- a/.github/actions/install_virtualbox/action.yml +++ /dev/null @@ -1,9 +0,0 @@ -name: Install virtualbox on Mac -description: Installs virtualbox on Mac runners -runs: - using: composite - steps: - - shell: bash - run: | - set -exo pipefail - brew install virtualbox vagrant diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c097c7c..41cb3ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,7 +11,7 @@ name: Build the boxes jobs: collect: name: Discover distros - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 outputs: distros: ${{ steps.distros.outputs.distros }} build: ${{ steps.time.outputs.time }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a452d8e..ac59205 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ name: Test the components of it jobs: validate: name: Validate Packer templates are reasonable - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - uses: ./.github/actions/setup @@ -34,7 +34,7 @@ jobs: collect: name: Collect all Ansible-related jobs - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 outputs: all: ${{ steps.zipped.outputs.scenarios }} steps: @@ -56,16 +56,18 @@ jobs: 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-12', 'scenario': m} for m in macos] + ub_zip = [{'os': 'ubuntu-22.04', 'scenario': u} for u in ubuntu] + mac_zip = [{'os': 'ubuntu-22.04', 'scenario': m} for m in macos] print("::set-output name=scenarios::" + json.dumps(ub_zip + mac_zip)) lint: name: Lint Ansible code - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 - - uses: ./.github/actions/setup + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup test environment + uses: ./.github/actions/setup with: ansible: true - name: Run lint @@ -83,7 +85,22 @@ jobs: steps: - uses: actions/checkout@v3 - uses: ./.github/actions/setup - - uses: ./.github/actions/install_virtualbox - if: startsWith(matrix.scenarios.os, 'macos') + - uses: ./.github/actions/install_packer + - name: Install libvirt + shell: bash + run: | + set -exo pipefail + sudo apt-get install libvirt-daemon-system + sudo usermod -a -G libvirt $USER + sudo systemctl start libvirtd + sudo ls -la /var/run/libvirt/ - name: Run scenario - run: tox -e "${{ matrix.scenarios.scenario }}" + run: | + set -ex + TOX="$(which tox)" + sudo -E su -m -c "groups && ${TOX} -e \"${{ matrix.scenarios.scenario }}\" -- --destroy=never" $USER + - name: Get possible output + if: ${{ failure() }} + run: | + set -x + cat /home/runner/.cache/molecule/init/ubuntu18/vagrant.err diff --git a/ansible/roles/init/molecule/ubuntu16/molecule.yml b/ansible/roles/init/molecule/ubuntu16/molecule.yml deleted file mode 100644 index 173d92c..0000000 --- a/ansible/roles/init/molecule/ubuntu16/molecule.yml +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 7f8c4df..0000000 --- a/ansible/roles/init/molecule/ubuntu16/verify.yml +++ /dev/null @@ -1,11 +0,0 @@ -- 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 index c5ce1ff..237c916 100644 --- a/ansible/roles/init/molecule/ubuntu18/molecule.yml +++ b/ansible/roles/init/molecule/ubuntu18/molecule.yml @@ -4,5 +4,6 @@ driver: name: libvirt platforms: - name: test-ubuntu18-init - image: ubuntu:18.04 - box: generic/ubuntu1804 + box: boxen/ubuntu-18.04-x86_64 + provider_options: + driver: qemu diff --git a/ansible/roles/virtualbox/molecule/ubuntu18/molecule.yml b/ansible/roles/virtualbox/molecule/ubuntu18/molecule.yml index 7193175..5713d55 100644 --- a/ansible/roles/virtualbox/molecule/ubuntu18/molecule.yml +++ b/ansible/roles/virtualbox/molecule/ubuntu18/molecule.yml @@ -1,8 +1,5 @@ driver: name: containers - provider: - name: libvirt platforms: - - name: test-ubuntu18-init + - name: test-ubuntu18-virtualbox image: ubuntu:18.04 - box: generic/ubuntu1804 diff --git a/ansible/roles/virtualbox/molecule/ubuntu20/molecule.yml b/ansible/roles/virtualbox/molecule/ubuntu20/molecule.yml index f570cba..4a9300e 100644 --- a/ansible/roles/virtualbox/molecule/ubuntu20/molecule.yml +++ b/ansible/roles/virtualbox/molecule/ubuntu20/molecule.yml @@ -1,8 +1,5 @@ driver: name: containers - provider: - name: libvirt platforms: - - name: test-ubuntu20-init + - name: test-ubuntu20-virtualbox image: ubuntu:20.04 - box: generic/ubuntu2004