From a773def431e72a854519b7da9b32d1cc07357e72 Mon Sep 17 00:00:00 2001 From: Jiri Konecny Date: Thu, 25 Jul 2024 15:11:13 +0200 Subject: [PATCH] Add test for rpm-ostree container UEFI support This test works similar to `rpm-ostree-container-bootc` test but it will also check for UEFI entry and boot the system in UEFI mode. It might be merged together with bootc test but RHEL-9 and RHEL-10 are failing there currently. --- rpm-ostree-container-uefi.ks.in | 66 ++++++++++++++++++++++++++++ rpm-ostree-container-uefi.sh | 77 +++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 rpm-ostree-container-uefi.ks.in create mode 100755 rpm-ostree-container-uefi.sh diff --git a/rpm-ostree-container-uefi.ks.in b/rpm-ostree-container-uefi.ks.in new file mode 100644 index 00000000..030bc02c --- /dev/null +++ b/rpm-ostree-container-uefi.ks.in @@ -0,0 +1,66 @@ +#test name: rpm-ostree-container-bootc +# https://github.com/rhinstaller/anaconda/pull/5399 +# +# Test the UEFI entry is created correctly and the system is bootable. +# This doesn't work so far on RHEL-9 and RHEL-10 so the test will be +# disabled there after this is implemented: +# * https://issues.redhat.com/browse/RHEL-40897 +# * https://issues.redhat.com/browse/RHEL-40896 +# +# Also this test is mostly a copy of rpm-ostree-container-bootc test +# and it could be merged when RHEL-9 and RHEL-10 is enabled. +# + +# Use the default settings. +%ksappend common/common_no_storage_and_payload.ks +# On Fedora enforce lvm scheme (overriding btrfs default) +%ksappend storage/ostreecontainer_autopart.ks + +ostreecontainer --no-signature-verification --remote=test-remote --stateroot=test-stateroot --url=@KSTEST_OSTREECONTAINER_URL@ + +# Reboot the installed system. +reboot + +# Validate on the first boot. +%ksappend validation/success_on_first_boot.ks + +%post +efibootmgr | grep "Boot0001" | grep "HD(1" +if [ $? -ne 0 ]; then + echo -e "EFI boot entry wasn't created properly:\n$(efibootmgr)" >> /root/RESULT +fi + +# Checks after boot +cat >> /var/lib/extensions/kickstart-tests/usr/libexec/kickstart-test.sh << 'EOF' + +# propagate any errors from %post validations +if [ -e /root/RESULT ]; then + cat /root/RESULT +fi + +# Check that state root 'test-stateroot' exists +if [ ! -d /ostree/deploy/test-stateroot ]; then + echo "Couldn't find 'test-stateroot' stateroot" +fi + +# Check that bootupd information is present +if [ ! -e /boot/bootupd-state.json ]; then + echo "/boot/bootupd-state.json not found on installed system after booting" +fi + +bootupctl --help &> /dev/null || echo "bootupctl command not available after booting" +bootc --help &> /dev/null || echo "bootc command not available after booting" + +expected_url="@KSTEST_OSTREECONTAINER_URL@" +remote_url="$(ostree remote show-url test-remote)" +if [ ${?} -ne 0 ]; then + echo "Couldn't list remote URL for 'test-remote'" >> /root/RESULT +fi + +if [ "${remote_url}" != "${expected_url}" ]; then + echo "Unexpected URL: ${remote_url}, expected ${expected_url}"" >> /root/RESULT +fi + + +EOF +%end diff --git a/rpm-ostree-container-uefi.sh b/rpm-ostree-container-uefi.sh new file mode 100755 index 00000000..20d71faa --- /dev/null +++ b/rpm-ostree-container-uefi.sh @@ -0,0 +1,77 @@ +# +# Copyright (C) 2023 Red Hat, Inc. +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions of +# the GNU General Public License v.2, or (at your option) any later version. +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY expressed or implied, including the implied warranties of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. You should have received a copy of the +# GNU General Public License along with this program; if not, write to the +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the +# source code or documentation are not subject to the GNU General Public +# License and may only be used or replicated with the express permission of +# Red Hat, Inc. +# + +# Ignore unused variable parsed out by tooling scripts as test tags metadata +# shellcheck disable=SC2034 +TESTTYPE="payload ostree bootc reboot skip-on-rhel-8 skip-on-rhel-9 skip-on-rhel-10" + +. ${KSTESTDIR}/functions.sh + +enable_uefi() { + echo "true" +} + +copy_interesting_files_from_system() { + local disksdir + disksdir="${1}" + + # Find disks. + local args + args=$(for d in ${disksdir}/disk-*img; do echo -a ${d}; done) + + # Use also iscsi disk if there is any. + if [[ -n ${iscsi_disk_img} ]]; then + args="${args} -a ${disksdir}/${iscsi_disk_img}" + fi + + # Grab files out of the installed system while it still exists. + # Grab these files: + # + # logs from Anaconda - whole /var/log/anaconda/ directory is copied out, + # this can be used for saving specific test output + # original-ks.cfg - the kickstart used for the test + # anaconda-ks.cfg - the kickstart saved after installation, useful for + # debugging + # RESULT - file from the test + # + # The location of aforementioned files is different in an ostree system + + root_device=$(guestfish ${args} <<< " + launch + lvs" | \ + grep root) + + for item in /ostree/deploy/test-stateroot/var/roothome/original-ks.cfg \ + /ostree/deploy/test-stateroot/var/roothome/anaconda-ks.cfg \ + /ostree/deploy/test-stateroot/var/roothome/anabot.log \ + /ostree/deploy/test-stateroot/var/log/anaconda/ \ + /ostree/deploy/test-stateroot/var/roothome/RESULT + do + guestfish ${args} <<< " + launch + mount ${root_device} / + copy-out '${item}' '${disksdir}' + " 2>/dev/null + done +} + +additional_runner_args() { + # Wait for reboot and shutdown of the VM, + # but exit after the specified timeout. + echo "--wait $(get_timeout)" +}