Skip to content

Commit

Permalink
Merge pull request #1260 from jkonecny12/add-bootc-leavebootorder-test
Browse files Browse the repository at this point in the history
Add test support of bootupd EUFI entry insertion
  • Loading branch information
jkonecny12 authored Aug 7, 2024
2 parents a613841 + e7591e0 commit 3ff80a3
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 3 deletions.
7 changes: 7 additions & 0 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ inject_ks_to_initrd() {
echo "true"
}

enable_uefi() {
# Run the VM in the UEFI mode.
# This will add '--boot uefi' argument to the virt-install script
# returns: "true" or "false"
echo "false"
}

EXTRA_BOOTOPTS=$(echo "${KSTEST_EXTRA_BOOTOPTS}" | tr ';' ' ')

DEFAULT_BASIC_BOOTOPTS="debug=1 inst.debug ${EXTRA_BOOTOPTS}"
Expand Down
40 changes: 40 additions & 0 deletions rpm-ostree-container-leavebootorder.ks.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#test name: rpm-ostree-container-bootorder
# https://github.com/rhinstaller/anaconda/pull/5399
#
# Test that ostree container installation works with leavebootorder.
# In this test bootupd should be able to do dualboot. For sanity
# of this test just check if bootupd is invoked with the correct
# arguments.
#

# Use the default settings.
%ksappend common/common.ks

# network
network --bootproto=dhcp
# l10n
keyboard us
lang en
timezone America/New_York
# user confguration
rootpw testcase

# On Fedora enforce lvm scheme (overriding btrfs default)
%ksappend storage/ostreecontainer_autopart.ks

# Test if UEFI entry is not created!
bootloader --leavebootorder --timeout 1

ostreecontainer --no-signature-verification --remote=test-remote --stateroot=test-stateroot --url=@KSTEST_OSTREECONTAINER_URL@


%post
# check if efibootmgr don't have entry to boot from a disk
efibootmgr | grep "HD("
if [ $? -eq 0 ]; then
echo "EFI boot entry was created with leavebootorder: $(efibootmgr)" >> /root/RESULT
fi

%ksappend validation/success_if_result_empty.ks

%end
71 changes: 71 additions & 0 deletions rpm-ostree-container-leavebootorder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#
# Copyright (C) 2024 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 uefi ostree bootc reboot skip-on-rhel-8"

. ${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
}
66 changes: 66 additions & 0 deletions rpm-ostree-container-uefi.ks.in
Original file line number Diff line number Diff line change
@@ -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
77 changes: 77 additions & 0 deletions rpm-ostree-container-uefi.sh
Original file line number Diff line number Diff line change
@@ -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 uefi 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)"
}
11 changes: 11 additions & 0 deletions scripts/launcher/lib/conf/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def __init__(self, iso_path, ks_paths):
self._timeout = None
self._runner_args = []
self._stage2_from_ks = False
self._enable_uefi = False

@property
def test_name(self):
Expand Down Expand Up @@ -381,3 +382,13 @@ def stage2_from_ks(self) -> bool:
def stage2_from_ks(self, value: list):
"""Set use installer image from location defined in kickstart"""
self._stage2_from_ks = value

@property
def enable_uefi(self) -> bool:
"""Start VM with UEFI bootloader"""
return self._enable_uefi

@enable_uefi.setter
def enable_uefi(self, value: list):
"""Set if VM should start with UEFI bootloader"""
self._enable_uefi = value
4 changes: 4 additions & 0 deletions scripts/launcher/lib/launcher_interface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ case $1 in
msg="$(inject_ks_to_initrd)"
ret=$?
;;
enable_uefi)
msg="$(enable_uefi)"
ret=$?
;;
stage2_from_ks)
msg="$(stage2_from_ks)"
ret=$?
Expand Down
3 changes: 3 additions & 0 deletions scripts/launcher/lib/shell_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ def _run_bool_shell_func(self, name):
def inject_ks_to_initrd(self):
return self._run_bool_shell_func("inject_ks_to_initrd")

def enable_uefi(self):
return self._run_bool_shell_func("enable_uefi")

def stage2_from_ks(self):
return self._run_bool_shell_func("stage2_from_ks")

Expand Down
11 changes: 9 additions & 2 deletions scripts/launcher/lib/virtual_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ class VirtualInstall(object):
def __init__(self, test_name, iso, ks_paths, disk_paths, log_check,
kernel_args=None, vcpu_count=1, memory=1024, vnc=None,
virtio_host="127.0.0.1", virtio_port=6080,
nics=None, boot=None, runner_args=None, stage2_from_ks=False):
nics=None, boot=None, runner_args=None,
stage2_from_ks=False, enable_uefi=False):
"""
Start the installation
Expand All @@ -80,6 +81,7 @@ def __init__(self, test_name, iso, ks_paths, disk_paths, log_check,
:param str boot: virt-install --boot option (used eg for ibft)
:param list runner_args: extra arguments to pass to the virt-install
:param bool stage2_from_ks: use stage2 from location defined in kickstart
:param bool enable_uefi: enable UEFI for VM
"""
super().__init__()

Expand All @@ -98,6 +100,7 @@ def __init__(self, test_name, iso, ks_paths, disk_paths, log_check,
self._boot = boot
self._runner_args = runner_args or []
self._stage2_from_ks = stage2_from_ks
self._enable_uefi = enable_uefi

self._label = subprocess.check_output(
["blkid", "-p", "--output=value", "--match-tag=LABEL", self._iso],
Expand Down Expand Up @@ -167,6 +170,9 @@ def _prepare_args(self):
if not self._stage2_from_ks:
extra_args += " inst.stage2=hd:CDLABEL={0}".format(udev_escape(self._label))

if self._enable_uefi:
args.extend(["--boot", "uefi"])

if self._boot:
# eg booting from ipxe to emulate ibft firmware
args.append("--boot")
Expand Down Expand Up @@ -278,7 +284,8 @@ def _start_virt_install(self, install_log):
nics=self._conf.networks,
boot=self._conf.boot_image,
runner_args=self._conf.runner_args,
stage2_from_ks=self._conf.stage2_from_ks)
stage2_from_ks=self._conf.stage2_from_ks,
enable_uefi=self._conf.enable_uefi)

virt.run()
virt.destroy(os.path.basename(self._conf.temp_dir))
Expand Down
1 change: 1 addition & 0 deletions scripts/launcher/run_one_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def _create_virtual_conf(self, log_path) -> VirtualConfiguration:
v_conf.networks = nics_args
v_conf.runner_args = self._shell.additional_runner_args()
v_conf.stage2_from_ks = self._shell.stage2_from_ks()
v_conf.enable_uefi = self._shell.enable_uefi()
v_conf.ram = ram

return v_conf
Expand Down
2 changes: 1 addition & 1 deletion scripts/probe_boot_iso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ DISCINFO_VER=$(isoinfo -R -x /.discinfo -i "$IMAGE" | sed -n '2 p')
if [ -n "$DISCINFO_VER" ]; then
# make sure it looks like a Fedora version name/number
if [ "$DISCINFO_VER" = "Rawhide" ] || [ $(echo $DISCINFO_VER | cut -d. -f1) -gt 30 ]; then
echo "NAME=Fedora"
echo "NAME=fedora"
echo "VERSION=$DISCINFO_VER"
exit 0
fi
Expand Down

0 comments on commit 3ff80a3

Please sign in to comment.