Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for bootupd/bootc ostree containers #1037

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions fragments/shared/validation/success_on_first_boot.ks
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Report success if no errors have been reported on the first boot.
# Additional tests can be implemented in /usr/libexec/kickstart-test.sh
# Additional tests can be implemented in /etc/kickstart-test.sh
# by the kickstart test that includes this fragment. This file is empty
# by default.

Expand All @@ -16,7 +16,7 @@ After=graphical.target

[Service]
Type=oneshot
ExecStart=/bin/sh /usr/libexec/kickstart-service.sh
ExecStart=/bin/sh /etc/kickstart-service.sh

[Install]
WantedBy=graphical.target
Expand All @@ -26,13 +26,13 @@ EOF

# Create a script with the actual test. Print errors to stdout.
# IMPORTANT: This file should be rewritten in tests!
touch /usr/libexec/kickstart-test.sh
touch /etc/kickstart-test.sh

# Create a script for the service
cat > /usr/libexec/kickstart-service.sh << 'EOF'
cat > /etc/kickstart-service.sh << 'EOF'

# Check error messages in the syslog.
error_messages="$(/bin/sh /usr/libexec/kickstart-test.sh)"
error_messages="$(/bin/sh /etc/kickstart-test.sh)"

if [[ ! -z "${error_messages}" ]]; then
echo "*** System has started with errors:" >> /root/RESULT
Expand Down
44 changes: 44 additions & 0 deletions rpm-ostree-container-bootc.ks.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#test name: rpm-ostree-container-bootc
# for bootc/bootupd
# depends on the referenced ostree container being bootable

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

# Set up the RPM OSTree source.
ostreecontainer --no-signature-verification --url=quay.io/centos-bootc/fedora-bootc:eln

# Reboot the installed system.
reboot

# Validate on the first boot.
%ksappend validation/success_on_first_boot.ks

%post

# Checks in %post
# Check the url of the remote.
url="$(ostree remote show-url default)"
if [ "${url}" != "quay.io/centos-bootc/fedora-bootc:eln" ]; then
echo "Unexpected URL: ${url}" >> /root/RESULT
fi

# Checks after boot
cat > /etc/kickstart-test.sh << 'EOF'

# propagate any errors from %post validations
if [ -e /root/RESULT ]; then
cat /root/RESULT
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 || echo "bootupctl command not available after booting"
bootc --help || echo "bootc command not available after booting"

EOF

%end
56 changes: 56 additions & 0 deletions rpm-ostree-container-bootc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# 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"

. ${KSTESTDIR}/functions.sh

kernel_args() {
# Enforce the Fedora-Silverblue configuration.
echo ${DEFAULT_BOOTOPTS} inst.profile=fedora-silverblue
}

validate() {
disksdir=$1
args=$(for d in ${disksdir}/disk-*img; do echo -a ${d}; done)

# There should be a /ostree/deploy/default/var/roothome/RESULT file with results in it.
# Check its contents and decide whether the test finally succeeded or not.
result=$(run_with_timeout ${COPY_FROM_IMAGE_TIMEOUT} "virt-cat ${args} /ostree/deploy/default/var/roothome/RESULT")
if [[ $? != 0 ]]; then
status=1
echo '*** The RESULT file does not exist in VM image.'
elif [[ "${result}" != "SUCCESS" ]]; then
status=1
echo "${result}"
fi

return ${status}
}

get_timeout() {
echo "80"
}

additional_runner_args() {
# Wait for reboot and shutdown of the VM,
# but exit after the specified timeout.
echo "--wait $(get_timeout)"
}