From 8c0cd12b01b7fa0d0f1c3d4d9e22133700892d67 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Mon, 23 Sep 2024 11:15:05 +0200 Subject: [PATCH] Add test for targets Signed-off-by: Itxaka --- .github/workflows/image-pr.yaml | 9 +++ .github/workflows/image.yaml | 15 ++++ .github/workflows/reusable-build-flavor.yaml | 2 +- .../reusable-install-test-target.yaml | 75 +++++++++++++++++++ tests/install_target_test.go | 48 ++++++------ 5 files changed, 124 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/reusable-install-test-target.yaml diff --git a/.github/workflows/image-pr.yaml b/.github/workflows/image-pr.yaml index 75695ef7d..3f41b028b 100644 --- a/.github/workflows/image-pr.yaml +++ b/.github/workflows/image-pr.yaml @@ -124,6 +124,15 @@ jobs: needs: - core-ubuntu-24-lts + install-target: + uses: ./.github/workflows/reusable-install-test-target.yaml + with: + flavor: ubuntu + flavor_release: "24.04" + secureboot: false + needs: + - core-ubuntu-24-lts + install-secureboot: uses: ./.github/workflows/reusable-install-test.yaml with: diff --git a/.github/workflows/image.yaml b/.github/workflows/image.yaml index 0e589d3a7..d47ab5225 100644 --- a/.github/workflows/image.yaml +++ b/.github/workflows/image.yaml @@ -79,6 +79,19 @@ jobs: - flavor: opensuse flavorRelease: leap-15.6 secureboot: false + install-target: + uses: ./.github/workflows/reusable-install-test-target.yaml + with: + flavor: ${{ matrix.flavor }} + flavor_release: ${{ matrix.flavorRelease }} + needs: + - core + strategy: + fail-fast: true + matrix: + include: + - flavor: "ubuntu" + flavorRelease: "24.04" install-secureboot: uses: ./.github/workflows/reusable-install-test.yaml with: @@ -414,6 +427,8 @@ jobs: - core - standard - install + - install-target + - install-secureboot - zfs - acceptance - bundles diff --git a/.github/workflows/reusable-build-flavor.yaml b/.github/workflows/reusable-build-flavor.yaml index ca595e6ce..30976cbfd 100644 --- a/.github/workflows/reusable-build-flavor.yaml +++ b/.github/workflows/reusable-build-flavor.yaml @@ -113,7 +113,7 @@ jobs: --FLAVOR_RELEASE=${{ inputs.flavor_release }} \ --BASE_IMAGE=${{ inputs.base_image }} \ --MODEL=${{ inputs.model }} \ - --FAMILY=${{ inputs.family }} --KAIROS_AGENT_DEV_BRANCH=accept_devices + --FAMILY=${{ inputs.family }} sudo mv build/* . sudo rm -rf build - name: Install kairos-agent (for versioneer) diff --git a/.github/workflows/reusable-install-test-target.yaml b/.github/workflows/reusable-install-test-target.yaml new file mode 100644 index 000000000..19a024c02 --- /dev/null +++ b/.github/workflows/reusable-install-test-target.yaml @@ -0,0 +1,75 @@ +name: Reusable workflow - install test target + +on: + workflow_call: + inputs: + flavor: + required: true + type: string + flavor_release: + required: true + type: string + secureboot: + required: false + type: boolean + +permissions: read-all +jobs: + test: + runs-on: kvm + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4 + - run: | + git fetch --prune --unshallow + - name: Download ISO + id: iso + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: kairos-${{ inputs.flavor }}-${{ inputs.flavor_release}}.iso.zip + - name: Install Go + uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5 + with: + go-version-file: tests/go.mod + cache-dependency-path: tests/go.sum + - name: Block all traffic to metadata ip # For cloud runners, the metadata ip can interact with our test machines + run: | + sudo iptables -I INPUT -s 169.254.169.254 -j DROP + sudo iptables -I OUTPUT -d 169.254.169.254 -j DROP + - name: Enable KVM group perms + run: | + sudo apt-get update + sudo apt-get install -y libvirt-clients libvirt-daemon-system libvirt-daemon virtinst bridge-utils qemu qemu-system-x86 qemu-system-x86 qemu-utils qemu-kvm acl udev + + # https://github.blog/changelog/2023-02-23-hardware-accelerated-android-virtualization-on-actions-windows-and-linux-larger-hosted-runners/ + # echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + # sudo udevadm control --reload-rules + # sudo udevadm trigger --name-match=kvm + # sudo usermod -a -G kvm,libvirt $USER + # + # TODO: Switch back to the above solution when we switch to the github runners + # https://askubuntu.com/a/1081326 + sudo setfacl -m u:runner:rwx /dev/kvm + - name: Tests + env: + USE_QEMU: true + KVM: true + MEMORY: 4000 + CPUS: 2 + DRIVE_SIZE: 30000 + CREATE_VM: true + FLAVOR: ${{ inputs.flavor }} + run: | + if [ "${{ inputs.secureboot }}" = "true" ]; then + export FIRMWARE=/usr/share/OVMF/OVMF_CODE.fd + fi + ls *.iso + export ISO=$PWD/$(ls *.iso) + echo "ISO is: $ISO" + cp tests/go.* . + go run github.com/onsi/ginkgo/v2/ginkgo -v --label-filter "install-test-target" --fail-fast -r ./tests + - uses: actions/upload-artifact@89ef406dd8d7e03cfd12d9e0a4a378f454709029 # v4 + if: failure() + with: + name: ${{ inputs.flavor }}.logs.zip + path: tests/**/logs/* + if-no-files-found: warn diff --git a/tests/install_target_test.go b/tests/install_target_test.go index 74aa6adee..59f1935fe 100644 --- a/tests/install_target_test.go +++ b/tests/install_target_test.go @@ -32,18 +32,18 @@ var _ = Describe("kairos install test different targets", Label("install-test-ta uuid, err := vm.Sudo("lsblk /dev/vda -o UUID -n") cc := fmt.Sprintf(`#cloud-config - install: - auto: true - reboot: true - device: /dev/disk/by-uuid/%s - - stages: - initramfs: - - name: "Set user and password" - users: - kairos: - passwd: "kairos" - hostname: kairos-{{ trunc 4 .Random }} +install: + auto: true + reboot: true + device: /dev/disk/by-uuid/%s + +stages: + initramfs: + - name: "Set user and password" + users: + kairos: + passwd: "kairos" + hostname: kairos-{{ trunc 4 .Random }} `, uuid) By("Using the following config") @@ -74,18 +74,18 @@ var _ = Describe("kairos install test different targets", Label("install-test-ta label, err := vm.Sudo("lsblk /dev/vda -o LABEL -n") cc := fmt.Sprintf(`#cloud-config - install: - auto: true - reboot: true - device: /dev/disk/by-label/%s - - stages: - initramfs: - - name: "Set user and password" - users: - kairos: - passwd: "kairos" - hostname: kairos-{{ trunc 4 .Random }} +install: + auto: true + reboot: true + device: /dev/disk/by-label/%s + +stages: + initramfs: + - name: "Set user and password" + users: + kairos: + passwd: "kairos" + hostname: kairos-{{ trunc 4 .Random }} `, label) By("Using the following config")