From: Lennart Poettering Date: Thu, 18 Jun 2026 09:04:31 +0000 (+0200) Subject: ci: add test-case for new cleanup logic X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5efc3f5f137c92b32854924b40767bc0ad99cd7d;p=thirdparty%2Fsystemd.git ci: add test-case for new cleanup logic --- diff --git a/test/units/TEST-72-SYSUPDATE.sh b/test/units/TEST-72-SYSUPDATE.sh index dc2b3fbb648..10c0f335f68 100755 --- a/test/units/TEST-72-SYSUPDATE.sh +++ b/test/units/TEST-72-SYSUPDATE.sh @@ -643,4 +643,219 @@ set -e [[ $rc -ne 134 ]] grep -F "Manifest hash at line 1 decoded to 31 bytes" "$WORKDIR/malformed-manifest/check-new.log" >/dev/null +# Check the "cleanup" verb and the underlying install database. A successful +# update must record an install database entry for every transfer that installs +# into the file system, and those entries must cover all installed resources +# (regular files as well as directories). Once the transfer file owning some +# resources is removed, "systemd-sysupdate cleanup" must delete the now-orphaned +# resources (and their install database entries), while leaving resources that +# are still owned by a transfer file untouched. +INSTALLDB="/var/lib/systemd/sysupdate/installdb" +CLEANUP="$WORKDIR/cleanup" +rm -rf "$CONFIGDIR" "$INSTALLDB" "$CLEANUP" +mkdir -p "$CONFIGDIR" "$CLEANUP/source" "$CLEANUP/target" + +# The "alpha" transfer installs plain regular files, while the "beta" transfer +# installs whole directories (each populated with a couple of files), to exercise +# the recursive removal of orphaned directory resources during cleanup. +cleanup_new_version() { + local version="${1:?}" + echo "$RANDOM" >"$CLEANUP/source/alpha-$version.bin" + rm -rf "$CLEANUP/source/beta-$version" + mkdir -p "$CLEANUP/source/beta-$version" + echo "$RANDOM" >"$CLEANUP/source/beta-$version/one.txt" + echo "$RANDOM" >"$CLEANUP/source/beta-$version/two.txt" + (cd "$CLEANUP/source" && sha256sum alpha-* >SHA256SUMS) +} + +# Number of install database entries (symlinks) currently recorded. +installdb_count() { + if [[ -d "$INSTALLDB" ]]; then + find "$INSTALLDB" -mindepth 1 -maxdepth 1 -type l | wc -l + else + echo 0 + fi +} + +# Assert that every resource (file or directory) currently installed in the +# target directory is covered by at least one install database entry (i.e. its +# name matches a recorded pattern that points at the target directory). +assert_installdb_covers_target() { + local f base link tgt path pattern glob covered + for f in "$CLEANUP/target"/*; do + [[ -e "$f" ]] || continue + base="$(basename "$f")" + covered=0 + while read -r link; do + tgt="$(readlink "$link")" + # Entries are stored as "/./". + path="${tgt%%/./*}" + pattern="${tgt#*/./}" + # Translate the sysupdate pattern into a shell glob (only @v is used here). + glob="${pattern//@v/*}" + # shellcheck disable=SC2053 + if [[ "$path" == "$CLEANUP/target" && "$base" == $glob ]]; then + covered=1 + break + fi + done < <(find "$INSTALLDB" -mindepth 1 -maxdepth 1 -type l) + [[ "$covered" -eq 1 ]] || { echo "Installed resource '$f' not covered by install database" >&2; exit 1; } + done +} + +# Verify the installed beta- directory matches its source. +verify_beta_synced() { + local version="${1:?}" + test -d "$CLEANUP/target/beta-$version" + cmp "$CLEANUP/source/beta-$version/one.txt" "$CLEANUP/target/beta-$version/one.txt" + cmp "$CLEANUP/source/beta-$version/two.txt" "$CLEANUP/target/beta-$version/two.txt" +} + +cat >"$CONFIGDIR/01-alpha.transfer" <"$CONFIGDIR/02-beta.transfer" <), and "cleanup +# --component-all" must clean up orphaned resources across *all* of them in one +# go. Set up two components, install a resource into each, then drop both transfer +# files and run a single "cleanup --component-all" — it must remove both +# components' resources (and their install database entries). +COMPALL="$WORKDIR/component-all" +rm -rf "$COMPALL" /run/sysupdate.comp-a.d /run/sysupdate.comp-b.d \ + /var/lib/systemd/sysupdate/installdb.comp-a /var/lib/systemd/sysupdate/installdb.comp-b +mkdir -p "$COMPALL/source" "$COMPALL/target-a" "$COMPALL/target-b" \ + /run/sysupdate.comp-a.d /run/sysupdate.comp-b.d + +echo "$RANDOM" >"$COMPALL/source/comp-a-v1.bin" +echo "$RANDOM" >"$COMPALL/source/comp-b-v1.bin" +(cd "$COMPALL/source" && sha256sum comp-* >SHA256SUMS) + +cat >/run/sysupdate.comp-a.d/01-comp-a.transfer </run/sysupdate.comp-b.d/01-comp-b.transfer <