diff --git a/tests/.fmf/version b/tests/.fmf/version new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/.fmf/version @@ -0,0 +1 @@ +1 diff --git a/tests/provision.fmf b/tests/provision.fmf new file mode 100644 index 0000000..fb4608e --- /dev/null +++ b/tests/provision.fmf @@ -0,0 +1,5 @@ +--- + +standard-inventory-qcow2: + qemu: + m: 8G diff --git a/tests/scripts/test_lorax.sh b/tests/scripts/test_lorax.sh new file mode 100755 index 0000000..36b01e4 --- /dev/null +++ b/tests/scripts/test_lorax.sh @@ -0,0 +1,172 @@ +#!/bin/bash +set -eux + +FAILANY=0 +BOOTISO=/var/tmp/lorax-rhel8-iso/images/boot.iso +KSNAME=rhel-minimal.ks +KS="/usr/share/doc/lorax/$KSNAME" +OUTISO=/var/tmp/out.iso +ISODIR=/var/tmp/iso +IMGDIR=/var/tmp/img +## Functions for testing mkkiso + + +function fail { + echo -e "\n\n#### ERROR: $1\n" + FAIL=1 + FAILANY=1 +} + +function status { + if [ "$FAIL" -eq 0 ]; then + echo -e "\n\n#### PASS: $1\n" + else + echo -e "\n\n#### FAIL: $1\n" + fi +} + +function running { + FAIL=0 + echo -e "\n\n#### RUN: $1\n" +} + +[ -e "$ISODIR" ] || mkdir "$ISODIR" +[ -e "$IMGDIR" ] || mkdir "$IMGDIR" + +# Only add kickstart +function ks_only { + running "Add kickstart to iso" + + mkksiso $KS $BOOTISO $OUTISO || exit 1 + mount $OUTISO $ISODIR || exit 1 + + test_ks + + status "Add kickstart" + umount "$IMGDIR" + umount "$ISODIR" +} + +function test_ks { + ## This all needs to be another function + # Is there a kickstart in / of the iso? + [ -e "$ISODIR/$KSNAME" ] || fail "Missing kickstart" + + # Is the kickstart in the BIOS config? + grep "inst.ks=.*$KSNAME" "$ISODIR/isolinux/isolinux.cfg" || fail "Missing isolinux.cfg kickstart entry" + + # Is the kickstart in the UEFI config? + mount "$ISODIR/images/efiboot.img" "$IMGDIR" || exit 1 + grep "inst.ks=.*$KSNAME" "$IMGDIR/EFI/BOOT/grub.cfg" || fail "Missing UEFI grub.cfg kickstart entry" +} + +# Add ks and cmdline +function ks_serial { + running "Add kickstart and serial cmdline" + + mkksiso -c "console=ttyS0,115200n8" $KS $BOOTISO $OUTISO || exit 1 + mount $OUTISO $ISODIR || exit 1 + + test_ks + test_ks_serial + + status "Add kickstart and serial cmdline" + umount "$IMGDIR" + umount "$ISODIR" +} + +function test_ks_serial { + + # Is the serial in the BIOS config? + grep "console=ttyS0,115200n8" "$ISODIR/isolinux/isolinux.cfg" || fail "Missing isolinux.cfg cmdline entry" + + # Is the serial in the UEFI config? + grep "console=ttyS0,115200n8" "$IMGDIR/EFI/BOOT/grub.cfg" || fail "Missing UEFI grub.cfg cmdline entry" +} + +# New VOLID +function new_volid { + running "Use a new VOLID" + + mkksiso -V "mkksiso-test" $KS $BOOTISO $OUTISO || exit 1 + mount $OUTISO $ISODIR || exit 1 + + test_ks + test_volid + + status "Use a new VOLID" + umount "$IMGDIR" + umount "$ISODIR" +} + +function test_volid { + # Is the VOLID in the BIOS config? + grep "hd:LABEL=mkksiso-test" "$ISODIR/isolinux/isolinux.cfg" || fail "Missing isolinux.cfg kickstart entry" + + # Is the VOLID in the UEFI config? + grep "hd:LABEL=mkksiso-test" "$IMGDIR/EFI/BOOT/grub.cfg" || fail "Missing UEFI grub.cfg kickstart entry" +} + +# Add extra files +function add_files { + running "Add files" + + mkksiso -a /etc/services $KS $BOOTISO $OUTISO || exit 1 + mount $OUTISO $ISODIR || exit 1 + + test_ks + test_files + + status "Add files" + umount "$IMGDIR" + umount "$ISODIR" +} + +function test_files { + [ -e "$ISODIR/services" ] || fail "Missing file from iso" +} + +# All of the changes +function run_all { + running "Use all the options" + + mkksiso -a /etc/services -V "mkksiso-test" -c "console=ttyS0,115200n8" $KS $BOOTISO $OUTISO || exit 1 + mount $OUTISO $ISODIR || exit 1 + + test_ks + test_ks_serial + test_volid + test_files + + status "Use all the options" + umount "$IMGDIR" + umount "$ISODIR" +} + + +if [ ! -e /usr/share/lorax/templates.d/80-rhel/ ]; then + echo "Failed to find lorax-templates-rhel templates in /usr/share/lorax/templates.d/" + exit 1 +fi + +# Gather up the list of system repo files and use them for lorax +REPOS=$(find /etc/yum.repos.d/ -maxdepth 1 -type f -name '*\.repo' -exec echo -n "--repo {} " \;) +if [ -z "$REPOS" ]; then + echo "No system repos found" + exit 1 +fi + +# NOTE: We must use --nomacboot because the test system doesn't have the hfsplus fs available +# Run lorax using the host's repository configuration file +running "Build boot.iso with lorax" +lorax --product="Red Hat Enterprise Linux" --version=8 --release=8 --volid="RHEL-8-test" \ + $REPOS --isfinal --nomacboot /var/tmp/lorax-rhel8-iso/ || exit 1 + +# Test mkksiso on the new boot.iso +ks_only +ks_serial +new_volid +add_files +run_all + +exit $FAILANY diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..842943e --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,19 @@ +--- +- hosts: localhost + roles: + - role: standard-test-source + tags: + - always + + - role: standard-test-basic + tags: + - classic + + required_packages: + - rpm-build + - lorax + + tests: + - lorax: + dir: scripts + run: ./test_lorax.sh