Skip to content

Commit

Permalink
Add rpmtests wrapper for container use
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dmnks authored and pmatilai committed Oct 11, 2023
1 parent cea7e09 commit 860b3d8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 12 deletions.
6 changes: 6 additions & 0 deletions tests/mktree.common
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion tests/mktree.fedora
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/mktree.podman
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
10 changes: 0 additions & 10 deletions tests/mktree.rootfs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions tests/rpmtests.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 860b3d8

Please sign in to comment.