tests: Add a lorax boot.iso test
This builds a boot.iso in the vm, copies it out, and boots it. The tests that run inside the boot.iso (/tests/lorax/test_boot_bootiso.sh) cannot use beakerlib so it needs to be a simple shell script returning 1 on failure along with a descriptive message.
This commit is contained in:
parent
da5ba2421e
commit
94b2b58d99
57
test/check-lorax
Executable file
57
test/check-lorax
Executable file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
|
||||
import tempfile
|
||||
import composertest
|
||||
|
||||
|
||||
class LoraxTestCase(composertest.ComposerTestCase):
|
||||
def setUp(self):
|
||||
self.setUpTestMachine()
|
||||
|
||||
# Upload the contents of the ./tests/ directory to the machine (it must have beakerlib already installed)
|
||||
self.machine.upload(["../tests"], "/")
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDownTestMachine()
|
||||
|
||||
def runLoraxTest(self, script):
|
||||
extra_env = []
|
||||
if self.sit:
|
||||
extra_env.append("COMPOSER_TEST_FAIL_FAST=1")
|
||||
|
||||
r = self.execute(["TEST=" + self.id(),
|
||||
*extra_env,
|
||||
"/tests/test_lorax.sh", script])
|
||||
self.assertEqual(r.returncode, 0)
|
||||
|
||||
def runShellTest(self, script):
|
||||
"""Run a shell script directly, without the beakerlib wrapper"""
|
||||
extra_env = []
|
||||
r = self.execute(["TEST=" + self.id(),
|
||||
*extra_env,
|
||||
script])
|
||||
self.assertEqual(r.returncode, 0)
|
||||
|
||||
|
||||
class TestLorax(LoraxTestCase):
|
||||
def test_boot_iso(self):
|
||||
self.runLoraxTest("/tests/lorax/test_build_bootiso.sh")
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="/var/tmp/lorax-test.") as tmpdir:
|
||||
# Copy the resulting iso and shut down the VM
|
||||
self.tearDownVirt(virt_dir="/var/tmp/test-results/*", local_dir=tmpdir)
|
||||
|
||||
# Boot the image, login with ssh (no key needed)
|
||||
self.setUpTestMachine(tmpdir + "/images/boot.iso")
|
||||
|
||||
# Upload the contents of the ./tests/ directory to the machine
|
||||
self.machine.upload(["../tests"], "/")
|
||||
|
||||
# Run the test on the booted image
|
||||
# NOTE: The boot.iso cannot run beakerlib so this test is called directly
|
||||
self.runShellTest("/tests/lorax/test_boot_bootiso.sh")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
composertest.main()
|
2
test/run
2
test/run
@ -11,6 +11,8 @@ if [ -n "$TEST_SCENARIO" ]; then
|
||||
test/check-cli TestQcow2
|
||||
elif [ "$TEST_SCENARIO" == "tar" ]; then
|
||||
test/check-cli TestTar
|
||||
elif [ "$TEST_SCENARIO" == "lorax" ]; then
|
||||
test/check-lorax TestLorax
|
||||
else
|
||||
test/check-cloud TestCloud.test_$TEST_SCENARIO
|
||||
fi
|
||||
|
4
tests/lorax/lib/lib.sh
Executable file
4
tests/lorax/lib/lib.sh
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# lorax specific functions
|
||||
|
||||
. "$(dirname $0)/../cli/lib/lib.sh"
|
17
tests/lorax/test_boot_bootiso.sh
Executable file
17
tests/lorax/test_boot_bootiso.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
# Note: execute this file from inside the booted boot.iso
|
||||
# We cannot use beakerlib because the boot.iso is missing some of the executables it depends on
|
||||
#
|
||||
|
||||
#####
|
||||
#
|
||||
# Test a booted boot.iso
|
||||
#
|
||||
#####
|
||||
|
||||
set -e
|
||||
|
||||
if ! grep anaconda /root/lorax-packages.log; then
|
||||
echo "ERROR: anaconda not included in boot.iso package list"
|
||||
exit 1
|
||||
fi
|
29
tests/lorax/test_build_bootiso.sh
Executable file
29
tests/lorax/test_build_bootiso.sh
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
# Note: execute this file from the project root directory
|
||||
|
||||
#####
|
||||
#
|
||||
# Builds a boot.iso with lorax
|
||||
#
|
||||
#####
|
||||
|
||||
set -e
|
||||
|
||||
. /usr/share/beakerlib/beakerlib.sh
|
||||
. "$(dirname $0)/lib/lib.sh"
|
||||
|
||||
CLI="${CLI:-./src/sbin/lorax}"
|
||||
|
||||
# Make up a name (slightly unsafe), should not exist before running lorax so use -u
|
||||
rlJournalStart
|
||||
rlPhaseStartTest "Build lorax boot.iso"
|
||||
rlAssertEquals "SELinux operates in enforcing mode" "$(getenforce)" "Enforcing"
|
||||
lorax -p Fedora-Lorax-Test -v "$RELEASE" -r "$RELEASE" \
|
||||
--repo /etc/yum.repos.d/fedora.repo \
|
||||
--sharedir "$SHARE_DIR" /var/tmp/test-results/
|
||||
rlAssertEquals "exit code should be zero" $? 0
|
||||
IMAGE="/var/tmp/test-results/images/boot.iso"
|
||||
rlAssertExists "$IMAGE"
|
||||
rlPhaseEnd
|
||||
rlJournalEnd
|
||||
rlJournalPrintText
|
86
tests/test_lorax.sh
Executable file
86
tests/test_lorax.sh
Executable file
@ -0,0 +1,86 @@
|
||||
#!/bin/bash
|
||||
# Note: execute this file from the project root directory
|
||||
#
|
||||
# Test building a boot.iso using lorax
|
||||
|
||||
set -eu
|
||||
|
||||
BEAKERLIB_DIR=$(mktemp -d /tmp/lorax-test.XXXXXX)
|
||||
CLI="${CLI:-}"
|
||||
export BEAKERLIB_DIR
|
||||
source /usr/share/beakerlib/beakerlib.sh
|
||||
|
||||
RELEASE=$(awk -F: '{ print $5 }' /etc/system-release-cpe)
|
||||
export RELEASE
|
||||
|
||||
function setup_tests {
|
||||
local share_dir=$1
|
||||
|
||||
# Make the boot.iso boot more quickly (isolinux.cfg)
|
||||
for cfg in "$share_dir"/templates.d/99-generic/config_files/*/isolinux.cfg; do
|
||||
sed -i.orig 's/^timeout.*/timeout 20/' "$cfg"
|
||||
sed -i 's/quiet$/inst.sshd=1 console=ttyS0,115200n8/' "$cfg"
|
||||
done
|
||||
|
||||
# Make the boot.iso boot more quickly (grub.conf)
|
||||
for cfg in "$share_dir"/templates.d/99-generic/config_files/*/grub.conf; do
|
||||
sed -i.orig 's/^timeout.*/timeout 2/' "$cfg"
|
||||
sed -i 's/quiet$/inst.sshd=1 console=ttyS0,115200n8/' "$cfg"
|
||||
done
|
||||
|
||||
# Make the boot.iso boot more quickly (grub2-efi.cfg)
|
||||
for cfg in "$share_dir"/templates.d/99-generic/config_files/*/grub2-efi.cfg; do
|
||||
sed -i.orig 's/^set timeout.*/set timeout=2/' "$cfg"
|
||||
sed -i 's/\(.*linux .* ro$\)/\1 inst.sshd=1 console=ttyS0,115200n8/' "$cfg"
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
function teardown_tests {
|
||||
local share_dir=$1
|
||||
|
||||
# Restore all the configuration files
|
||||
for cfg in "$share_dir"/templates.d/99-generic/config_files/*/*.orig; do
|
||||
mv "$cfg" "${cfg%%.orig}"
|
||||
done
|
||||
}
|
||||
|
||||
SHARE_DIR=$(mktemp -d '/tmp/lorax-share.XXXXX')
|
||||
export SHARE_DIR
|
||||
if [ -z "$CLI" ]; then
|
||||
cp -R /usr/share/lorax/* "$SHARE_DIR"
|
||||
else
|
||||
top_srcdir=$(pwd)
|
||||
export top_srcdir
|
||||
source ./tests/testenv.sh
|
||||
cp -R ./share/* "$SHARE_DIR"
|
||||
fi
|
||||
chmod a+rx -R "$SHARE_DIR"
|
||||
setup_tests "$SHARE_DIR"
|
||||
|
||||
export BEAKERLIB_JOURNAL=0
|
||||
|
||||
if [ -z "$*" ]; then
|
||||
# Run all the lorax tests
|
||||
for t in ./tests/lorax/test_*sh; do
|
||||
$t
|
||||
done
|
||||
else
|
||||
# execute other tests which need more adjustments in the calling environment
|
||||
# or can't be executed inside Travis CI
|
||||
for TEST in "$@"; do
|
||||
$TEST
|
||||
done
|
||||
fi
|
||||
|
||||
|
||||
teardown_tests "$SHARE_DIR"
|
||||
|
||||
source "$BEAKERLIB_DIR/TestResults"
|
||||
|
||||
if [ $TESTRESULT_RESULT_ECODE != 0 ]; then
|
||||
echo "Test failed. Leaving log in $BEAKERLIB_DIR"
|
||||
exit $TESTRESULT_RESULT_ECODE
|
||||
fi
|
||||
|
||||
rm -rf "$BEAKERLIB_DIR"
|
Loading…
Reference in New Issue
Block a user