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

New test - rpm-ostree-container-bootc + related improvements #1096

Closed
wants to merge 4 commits into from
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
12 changes: 12 additions & 0 deletions containers/runner/launch
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ if [ "${CRUN%podman*}" != "$CRUN" ] && [ $(id -u) -ne 0 ]; then
PODMAN_SELINUX_FIX="--security-opt label=disable"
fi

# Build up a list of KSTEST_* environment variables to be passed into the container
TEST_ENV_VARS=$(printenv | while read line; do
key="$(echo $line | cut -d'=' -f1)"
val="$(echo $line | cut -d'=' -f2-)"

if [[ "${key}" =~ ^KSTEST_ ]]; then
echo -n " --env ${key}=${val//&/\\&}"
fi
done)

# Run container against the local repository, to test changes easily
# Expose the container's libvirt to the host; check "podman ps" for the port, and use e.g.:
# virsh -c qemu+tcp://localhost:<port>/session list
Expand All @@ -149,5 +159,7 @@ $CRUN run -it --rm --device=/dev/kvm --publish 127.0.0.1::16509 $PODMAN_SELINUX_
--env KSTESTS_TEST="$KSTESTS_TEST" --env TESTTYPE="${TESTTYPE:-}" --env SKIP_TESTTYPES="${SKIP_TESTTYPES:-}" \
--env KSTESTS_RUN_TIMEOUT="${TIMEOUT:-}" \
--env TEST_JOBS="$TEST_JOBS" --env PLATFORM="${PLATFORM:-}" --env TEST_RETRY="${TEST_RETRY:-}" ${UPDATES_IMG_ARGS:-} ${CONTAINER_RUN_ARGS:-} \
--env KSTESTS_KEEP=${KSTESTS_KEEP:-1} \
${TEST_ENV_VARS} \
${VAR_TMP:-} -v "$PWD/data:/opt/kstest/data:z" -v "$BASEDIR:/kickstart-tests:ro,z" ${DEFAULTS_SH_ARGS:-} \
$CONTAINER $RUN_COMMAND
6 changes: 4 additions & 2 deletions containers/runner/run-kstest
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ ${KSTESTS_DIR}/scripts/log2json --scenario $SCENARIO --output $TEST_LOG.json $TE
# Fixup permissions
chmod -R a+rw /var/tmp/kstest-*
# Clean up (artifacts from broken test)
find /var/tmp/kstest-* -name "*.iso" -delete
find /var/tmp/kstest-* -name "*.img" -delete
if [ "$KSTESTS_KEEP" != "2" ]; then
find /var/tmp/kstest-* -name "*.iso" -delete
find /var/tmp/kstest-* -name "*.img" -delete
fi
cp $TEST_LOG ${LOGS_DIR}
cp $TEST_LOG.json ${LOGS_DIR}
cp /var/tmp/kstest-list ${LOGS_DIR}
Expand Down
23 changes: 19 additions & 4 deletions fragments/shared/validation/success_on_first_boot.ks
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
# by the kickstart test that includes this fragment. This file is empty
# by default.

# A somewhat different approach via systemd-sysext/overlayfs is needed
# in ostree systems with read-only /usr

%post
# detect if the system uses ostree and change path prefix if needed
if ostree admin status &> /dev/null; then
# based on info from https://www.reddit.com/r/Fedora/comments/wir3cq/comment/ijhjfah
mkdir -p /var/lib/extensions/kickstart-tests/usr/lib/extension-release.d \
/var/lib/extensions/kickstart-tests/usr/libexec
cp /etc/os-release /var/lib/extensions/kickstart-tests/usr/lib/extension-release.d/extension-release.kickstart-tests
script_prefix="/var/lib/extensions/kickstart-tests"
systemd-sysext merge
systemctl enable systemd-sysext
else
script_prefix=""
fi

# Create a systemd service.
cat > /etc/systemd/system/kickstart-test.service << EOF
Expand All @@ -16,7 +31,7 @@ After=graphical.target

[Service]
Type=oneshot
ExecStart=/bin/sh /usr/libexec/kickstart-service.sh
ExecStart=/bin/sh ${script_prefix}/usr/libexec/kickstart-service.sh

[Install]
WantedBy=graphical.target
Expand All @@ -26,13 +41,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 ${script_prefix}/usr/libexec/kickstart-test.sh

# Create a script for the service
cat > /usr/libexec/kickstart-service.sh << 'EOF'
cat > ${script_prefix}/usr/libexec/kickstart-service.sh << 'EOF'

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

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

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

# The RPM OSTree source is set up by the test script

# Reboot the installed system.
reboot

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

%post
# Checks in %post
# Check of the remote URL is appended by the test script

# Checks after boot
cat >> /opt/kickstart-tests/kickstart-test.sh << 'EOF'
Copy link
Contributor

@rvykydal rvykydal Mar 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part was failing for me with file not found, updated here: #1116


# 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"

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

. ${KSTESTDIR}/functions.sh

os_major=${KSTEST_OS_VERSION%%.*}
if [ "${KSTEST_OS_NAME}" == "rhel" ]; then
container_url="quay.io/centos-bootc/centos-bootc:stream${os_major}"
else
container_url="quay.io/centos-bootc/fedora-bootc:eln"
fi

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
}

prepare() {
ks=${1}
cat >> ${ks} << EOF1
ostreecontainer --no-signature-verification --remote=test-remote --stateroot=test-stateroot --url=${container_url}

%post
cat >> /var/lib/extensions/kickstart-tests/usr/libexec/kickstart-test.sh << EOF2
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}" != "${container_url}" ]; then
echo "Unexpected URL: \\\${remote_url}, expected ${container_url}" >> /root/RESULT
fi
EOF2
%end
EOF1
echo ${ks}
}

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)"
}
2 changes: 2 additions & 0 deletions scripts/run_kickstart_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ if [[ $? -ne 0 ]]; then
fi
ISO_OS_NAME=$(echo "${output}" | grep 'NAME=')
ISO_OS_NAME="${ISO_OS_NAME##NAME=}"
export KSTEST_OS_NAME="${ISO_OS_NAME}"
ISO_OS_VERSION=$(echo "${output}" | grep 'VERSION=')
ISO_OS_VERSION="${ISO_OS_VERSION##VERSION=}"
export KSTEST_OS_VERSION="${ISO_OS_VERSION}"


# Append sed args to substitute
Expand Down
Loading