test: Reinstate podman as default runner

Partial revert of 23469bbe3b. When running tests in a GitHub action,
we do not want to run as host root user. Therefore, restore podman as
the default runner, but make sure to prefer docker when attaching to
the host network namespace.
This commit is contained in:
Tobias Waldekranz
2024-05-20 16:21:06 +02:00
parent 508e2287b8
commit 7bb48ece49
3 changed files with 34 additions and 8 deletions
+18 -1
View File
@@ -8,16 +8,33 @@ ixdir=$(readlink -f "$testdir/..")
logdir=$(readlink -f "$testdir/.log")
envdir="$HOME/.infix-test-venv"
qeneth="$testdir/qeneth/qeneth"
runners="podman docker"
build_ps1()
{
echo "\e[1m\$(date \"+%H:%M:%S\") \h$1\e[0m:\W # "
}
#
# Figure out available container runner
#
runner()
{
for r in $runners; do
which $r >/dev/null && {
echo $r
return
}
done
echo "ERROR: No container manager found (tried \"$runners\")" >&2
exit 1
}
#
# Returns the latest started infamy container
#
infamy()
{
docker ps -f name='infamy.*' --format '{{.Names}}' |tail -1
$(runner) ps -f name='infamy.*' --format '{{.Names}}' |tail -1
}
+15 -6
View File
@@ -23,6 +23,11 @@ usage: test/env [<OPTS>] -f <IMAGE> -q <QENETH-DIR> <COMMAND> [<ARGS>...]
Don't containerize the command, run it directly in the current
namespaces
-D
Prefer Docker over podman. This is implied when -t is specified,
as podman does not allow the necessary network permissions to be
granted to the container
-f <IMAGE>
Specify images required for test, squashfs image is required
if testing with kernel. bios and disk image is required if
@@ -86,7 +91,7 @@ name()
nm=infamy
id=0
names=$(docker ps -f name='infamy.*' --format '{{.Names}}')
names=$($(runner) ps -f name='infamy.*' --format '{{.Names}}')
while true; do
name="$nm$id"
unset hit
@@ -112,17 +117,20 @@ containerize=yes
[ -c /dev/kvm ] && kvm="--device=/dev/kvm"
files=
while getopts "cCf:hiKp:q:t:" opt; do
while getopts "cCDf:hiKp:q:t:" opt; do
case ${opt} in
c)
docker image prune -af
docker volume prune -f
docker container prune -f
$(runner) image prune -af
$(runner) volume prune -f
$(runner) container prune -f
exit 0
;;
C)
containerize=
;;
D)
runners="docker podman"
;;
f)
files="$files $OPTARG"
;;
@@ -145,6 +153,7 @@ while getopts "cCf:hiKp:q:t:" opt; do
t)
topology="$OPTARG"
network="--network host --volume $topology:$topology:ro"
runners="docker podman"
;;
*)
>&2 echo "Unknown option -$opt"
@@ -156,7 +165,7 @@ done
if [ "$containerize" ]; then
# shellcheck disable=SC2016
exec docker run \
exec $(runner) run \
--cap-add=NET_RAW \
--cap-add=NET_ADMIN \
--device=/dev/net/tun \
+1 -1
View File
@@ -17,4 +17,4 @@ usage()
sys=$1
[ -n "$sys" ] || sys=$(infamy)
docker exec -it --workdir "$ixdir/test" "$sys" ./env -C sh
$(runner) exec -it --workdir "$ixdir/test" "$sys" ./env -C sh