Skip to content

Commit

Permalink
Improve compose tests
Browse files Browse the repository at this point in the history
* Add traps to report setup, tests, and teardown errors as failures
* Pass through return code of podman commands
* Fix unset variables
* Fix simple_port_map image build when installing flask (PEP 668 - externally managed environment error)
* Ignore kill errors in slirp4netns_opts teardown steps

Signed-off-by: Gavin Lam <[email protected]>
  • Loading branch information
gavinkflam committed Dec 16, 2023
1 parent 07834ab commit ccc3eb7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion test/compose/simple_port_map/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine
WORKDIR /app
RUN apk update && apk add py3-pip && pip3 install flask
RUN apk update && apk add py3-flask
COPY . /app
ENTRYPOINT ["python3"]
CMD ["app.py"]
2 changes: 1 addition & 1 deletion test/compose/slirp4netns_opts/teardown.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- bash -*-

kill $nc_pid &> /dev/null
kill $nc_pid &> /dev/null || true
rm -f $OUTFILE
30 changes: 22 additions & 8 deletions test/compose/test-compose
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Usage: test-compose [testname]
#
set -Eu
ME=$(basename $0)

###############################################################################
Expand Down Expand Up @@ -240,7 +241,10 @@ function podman() {
--runroot $WORKDIR/runroot \
--network-config-dir $WORKDIR/cni \
"$@")
rc=$?

echo -n "$output" >>$WORKDIR/output.log
return $rc
}

###################
Expand Down Expand Up @@ -300,8 +304,8 @@ for t in "${tests_to_run[@]}"; do
testdir="$(dirname $t)"
testname="$(basename $testdir)"

if [ -e $test_dir/SKIP ]; then
reason="$(<$test_dir/SKIP)"
if [ -e $testdir/SKIP ]; then
reason="$(<$testdir/SKIP)"
if [ -n "$reason" ]; then
reason=" - $reason"
fi
Expand All @@ -315,13 +319,21 @@ for t in "${tests_to_run[@]}"; do
(
cd $testdir || die "Cannot cd $testdir"

if [ -e teardown.sh ]; then
trap 'teardown' EXIT
function teardown() {
trap '_show_ok 0 "$testname - teardown" "[ok]" "[error]"' ERR
. teardown.sh
trap - ERR
}
fi

# setup file may be used for creating temporary directories/files.
# We source it so that envariables defined in it will get back to us.
if [ -e setup.sh ]; then
trap '_show_ok 0 "$testname - setup" "[ok]" "[error]"' ERR
. setup.sh
fi
if [ -e teardown.sh ]; then
trap '. teardown.sh' 0
trap - ERR
fi

podman compose up -d &> $logfile
Expand All @@ -337,11 +349,13 @@ for t in "${tests_to_run[@]}"; do
# Run tests. This is likely to be a series of 'test_port' checks
# but may also include podman commands to inspect labels, state
if [ -e tests.sh ]; then
trap '_show_ok 0 "$testname - tests" "[ok]" "[error]"' ERR
. tests.sh
trap - ERR
fi
# FIXME: if any tests fail, try 'podman logs' on container?

if [ -n "$COMPOSE_WAIT" ]; then
if [ -n "${COMPOSE_WAIT:-}" ]; then
echo -n "Pausing due to \$COMPOSE_WAIT. Press ENTER to continue: "
read keepgoing
fi
Expand Down Expand Up @@ -379,8 +393,8 @@ done
test_count=$(<$testcounter_file)
failure_count=$(<$failures_file)

if [ -z "$PODMAN_TESTS_KEEP_WORKDIR" ]; then
if ! is_rootless; then
if [ -z "${PODMAN_TESTS_KEEP_WORKDIR:-}" ]; then
if ! is_rootless; then
rm -rf $WORKDIR
else
$PODMAN_BIN unshare rm -rf $WORKDIR
Expand Down

0 comments on commit ccc3eb7

Please sign in to comment.