From 15b436cb1b772960b50b1a8027a60c280dc0ec54 Mon Sep 17 00:00:00 2001 From: "Jason N." <33561705+JasonN3@users.noreply.github.com> Date: Mon, 4 Mar 2024 17:28:12 -0500 Subject: [PATCH] add tests --- .github/workflows/build-and-test.yml | 47 ++++++++++++++++++---------- tests/iso/README.md | 1 + tests/iso/os-release.sh | 30 ++++++++++++++++++ tests/vm/README.md | 1 + 4 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 tests/iso/README.md create mode 100644 tests/iso/os-release.sh create mode 100644 tests/vm/README.md diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index e8c2281..a10fbb8 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -111,10 +111,13 @@ jobs: contents: read packages: write steps: + - name: Checkout repo + uses: actions/checkout@v4 + - name: Ensure qemu is installed run: | sudo apt-get update - sudo apt-get install -y qemu qemu-utils xorriso unzip qemu-system-x86 netcat socat jq isomd5sum + sudo apt-get install -y qemu qemu-utils xorriso unzip qemu-system-x86 netcat socat jq isomd5sum ansible - name: Create disk run: | @@ -128,6 +131,17 @@ jobs: - name: Verify ISO run: checkisomd5 ${{ env.IMAGE_NAME }}-${{ env.VERSION }}.iso + - name: Run ISO checks + run: | + for check in $(ls tests/iso) + do + if [[ -f $check && $check != "README.md" ]] + then + chmod +x $check + ./${check} ${{ env.IMAGE_NAME }}-${{ env.VERSION }}.iso + fi + done + - name: Add Kickstart and Grub options to ISO run: | sudo mkdir /mnt/iso @@ -184,20 +198,19 @@ jobs: timeout 30m bash -c "while ! (grep 'login:' vm.stdout); do sleep 1; done" - VM_IP=$({ echo '{"execute": "guest-network-get-interfaces"}'; sleep 2; } | socat unix-connect:/tmp/qga.sock - | jq -r '.return[1]["ip-addresses"][] | select(."ip-address-type"=="ipv4") | .["ip-address"]') - echo "VM ready for tests at IP ${VM_IP}" - #if ! (echo /dev/tcp/${VM_IP}/22) - #then - echo ${VM_USER} >> vm.stdin - - timeout 30m bash -c "while ! (grep 'Password:' vm.stdout); do sleep 1; done" - echo > vm.stdout - echo ${VM_PASS} >> vm.stdin - - timeout 30m bash -c "while ! (grep '#' vm.stdout); do sleep 1; done" - echo > vm.stdout - echo "dnf install -y openssh; systemctl enable --now sshd" - timeout 30m bash -c "while ! (grep '#' vm.stdout); do sleep 1; done" - #fi + export VM_IP=$({ echo '{"execute": "guest-network-get-interfaces"}'; sleep 2; } | socat unix-connect:/tmp/qga.sock - | jq -r '.return[1]["ip-addresses"][] | select(."ip-address-type"=="ipv4") | .["ip-address"]') + if ! (echo /dev/tcp/${VM_IP}/22) + then + echo "SSH must be installed and enabled inside the container" + fi - echo "VM ready for tests at IP ${VM_IP}" \ No newline at end of file + echo "VM ready for tests at IP ${VM_IP}" + for check in $(ls tests/vm) + do + if [[ -f $check && $check != "README.md" ]] + then + chmod +x $check + ./${check} + fi + done + diff --git a/tests/iso/README.md b/tests/iso/README.md new file mode 100644 index 0000000..bd511d9 --- /dev/null +++ b/tests/iso/README.md @@ -0,0 +1 @@ +Place scripts that will test the ISO. The ISO file will be passed as the first argument \ No newline at end of file diff --git a/tests/iso/os-release.sh b/tests/iso/os-release.sh new file mode 100644 index 0000000..c9e38d6 --- /dev/null +++ b/tests/iso/os-release.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +iso=$1 + +dnf install -y squashfs-tools + +mkdir /mnt/{iso,install} + +# Mount ISO +mount -o loop $iso /mnt/iso + +# Mount squashfs +mount -t squashfs -o loop /mnt/iso/images/install.img /mnt/install + +FOUND_VERSION=$(cat /mnt/install/os-release | grep VERSION_ID | cut -d= -f2) + +# Cleanup +umount /mnt/install +umount /mnt/iso + +if [[ ${FOUND_VERSION} != ${VERSION} ]] +then + echo "Version mismatch" + echo "Expected: ${VERSION}" + echo "Found: ${FOUND_VERSION}" + exit 1 +else + echo "Correct version found" + exit 0 +fi \ No newline at end of file diff --git a/tests/vm/README.md b/tests/vm/README.md new file mode 100644 index 0000000..39840b4 --- /dev/null +++ b/tests/vm/README.md @@ -0,0 +1 @@ +Place scripts that will test the VM. The VM will be available at ${VM_IP} using username ${VM_USER} and password ${VM_PASS} \ No newline at end of file