Files
systemd/test/integration-test-setup.sh
T
Daan De Meyer af153e36ae test: Add a way to quickly iterate on an integration test
Rebuilding the integration test every time is very slow. Let's
introduce a way to iterate on an integration test without rebuilding
the image every time. By making a btrfs snapshot before we run the
integration test, we can then systemctl soft-reboot after running
the test to restore the rootfs to a pristine state before running
the test again.

As /run/nextroot will get nuked on reboot or soft-reboot, we introduce
a tmpfiles snippet to make sure it is recreated every (soft-)reboot
and adapt the existing tests to deal with this new symlink.
2024-08-05 15:13:38 +02:00

57 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e
case "$1" in
setup)
if [[ -f "$STATE_DIRECTORY/inprogress" ]]; then
exit 0
fi
if [[ -d /snapshot ]]; then
echo "Run systemctl soft-reboot first to make sure the test runs within a pristine rootfs" >&2
exit 1
fi
. /usr/lib/os-release
if test -n "$(shopt -s nullglob; echo /work/build/*.{rpm,deb,pkg.tar})"; then
case "$ID" in
arch)
pacman --upgrade --needed --noconfirm /work/build/*.pkg.tar
;;
debian|ubuntu)
apt-get install /work/build/*.deb
;;
opensuse*)
zypper --non-interactive install --allow-unsigned-rpm /work/build/*.rpm
;;
centos|fedora)
dnf upgrade --assumeyes --disablerepo="*" /work/build/*.rpm
;;
*)
echo "Unknown distribution $ID" >&2
exit 1
esac
fi
# TODO: Use a proper flat btrfs subvolume layout once we can create subvolumes without privileged in
# systemd-repart (see https://github.com/systemd/systemd/pull/33498). Until that's possible, we nest
# snapshots within each other.
if command -v btrfs >/dev/null && [[ "$(stat --file-system --format %T /)" == "btrfs" ]]; then
btrfs subvolume snapshot / /snapshot
fi
touch "$STATE_DIRECTORY/inprogress"
;;
finalize)
# If we're rebooting, the test does a reboot as part of its execution and we shouldn't remove /inprogress.
if ! [[ "$(systemctl list-jobs)" =~ reboot.target|kexec.target|soft-reboot.target ]]; then
rm -f "$STATE_DIRECTORY/inprogress"
fi
;;
*)
echo "Unknown verb $1" >&2
exit 1
esac