From 860b3d82fadd3f9c06c4048337d6200fb1a0a3ba Mon Sep 17 00:00:00 2001 From: Michal Domonkos Date: Tue, 10 Oct 2023 14:18:04 +0200 Subject: [PATCH] Add rpmtests wrapper for container use This script replaces the role of mktree.rootfs in the podman image where it serves as a wrapper for the bundled rpmtests that makes it store its working files in the current directory (bind mounted from host) by using an ugly symlink hack. The built in -C option can't be used here because it looks for atlocal in the destination directory where it obviously isn't, hence the hack. However, calling "mktree check" in the container is pretty confusing so move the hack out into a separate rpmtests wrapper so that we can just call "rpmtests" as one would expect. This also makes the hack more explicit and obvious. For consistency, use the same wrapper when running from the build dir (mktree.fedora) as well. Still prefer the locally built test scripts, though, and don't print the test log if not asked. --- tests/mktree.common | 6 ++++++ tests/mktree.fedora | 2 +- tests/mktree.podman | 2 +- tests/mktree.rootfs | 10 ---------- tests/rpmtests.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 12 deletions(-) create mode 100755 tests/rpmtests.sh diff --git a/tests/mktree.common b/tests/mktree.common index 83591de5fe..3bb8692547 100644 --- a/tests/mktree.common +++ b/tests/mktree.common @@ -3,6 +3,7 @@ make_install() { export DESTDIR=$1 local ld_conf_dir=$DESTDIR/@CMAKE_INSTALL_SYSCONFDIR@/ld.so.conf.d + local script_dir=/usr/share/mktree @CMAKE_MAKE_PROGRAM@ -C @CMAKE_BINARY_DIR@ install mkdir -p $ld_conf_dir @@ -13,6 +14,11 @@ make_install() mkdir -p $DESTDIR/usr/bin cp @TESTPROG_NAMES@ $DESTDIR/usr/bin/ + ln -s $script_dir/rpmtests.sh $DESTDIR/usr/bin/rpmtests + + mkdir -p $DESTDIR/$script_dir + cp rpmtests atlocal mktree.common $DESTDIR/$script_dir/ + cp @CMAKE_CURRENT_SOURCE_DIR@/rpmtests.sh $DESTDIR/$script_dir/ mkdir -p $DESTDIR/build ln -sf ../data/SOURCES $DESTDIR/build/ diff --git a/tests/mktree.fedora b/tests/mktree.fedora index f5932360a4..e7268d638f 100755 --- a/tests/mktree.fedora +++ b/tests/mktree.fedora @@ -190,7 +190,7 @@ case $CMD in check) mount_tree --read-only snapshot exec --tmpfs /tmp --bind $PWD $PWD --setenv RPMTREE $RPMTREE \ - sh -c 'cd '$PWD' && exec ./rpmtests "$@"' rpmtests "$@" + rpmtests -C $PWD "$@" ;; reset) rm -rf "$SANDBOX_DIR" diff --git a/tests/mktree.podman b/tests/mktree.podman index a44e51f0ac..012365620a 100755 --- a/tests/mktree.podman +++ b/tests/mktree.podman @@ -42,7 +42,7 @@ case $CMD in esac $PODMAN run --privileged -it --rm --read-only --tmpfs /tmp \ -v /srv --workdir /srv -e ROOTLESS=$ROOTLESS \ - --env RPMTREE=/ $OPTS $IMAGE mktree check "$@" + --env RPMTREE=/ $OPTS $IMAGE rpmtests --log "$@" ;; reset) $PODMAN stop $NAME >/dev/null && diff --git a/tests/mktree.rootfs b/tests/mktree.rootfs index 9f1b495fef..43eebfa81f 100755 --- a/tests/mktree.rootfs +++ b/tests/mktree.rootfs @@ -7,24 +7,14 @@ # The / filesystem should be read-only to prevent parallel tests from altering # it (online changes to an underlying filesystem are disallowed in OverlayFS). -DATA_DIR=/usr/share/mktree - CMD=$1; shift case $CMD in build) source ./mktree.common make_install / - - mkdir -p $DATA_DIR - cp $0 /usr/bin/ - cp rpmtests atlocal mktree.common $DATA_DIR/ ;; check) - ln -s $DATA_DIR/* . ./rpmtests "$@" - RC=$? - cat rpmtests.log - exit $RC ;; *) echo "Unsupported command." >&2 diff --git a/tests/rpmtests.sh b/tests/rpmtests.sh new file mode 100755 index 0000000000..e821d9dffc --- /dev/null +++ b/tests/rpmtests.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# +# Wrapper for rpmtests that looks for atlocal in the script's directory instead +# of $PWD or the one specified with -C. In addition, implements the -L | --log +# option to print the test log when done. + +SCRIPT_DIR=$(dirname $(readlink -f $0)) +SCRIPT_FILES="rpmtests atlocal mktree.common" + +TARGET_DIR=$PWD +PRINT_LOG=0 + +cd "$SCRIPT_DIR" + +while [ $# != 0 ]; do + case $1 in + -C | --directory ) + TARGET_DIR="$2" + shift + ;; + -L | --log ) + PRINT_LOG=1 + ;; + *) + break + ;; + esac + shift +done + +# Symlink script files into $TARGET_DIR, prefer local versions though +for file in $SCRIPT_FILES; do + [ -f "$TARGET_DIR/$file" ] || ln -s $PWD/$file $TARGET_DIR/ +done + +cd "$TARGET_DIR" + +# Run the test suite +./rpmtests "$@"; RC=$? +[ $PRINT_LOG == 1 ] && cat rpmtests.log + +# Clean up the symlinks +for file in $SCRIPT_FILES; do + [ -L "$file" ] && rm "$file" +done + +exit $RC