Merge pull request #16993 from edsantiago/bats_remote

[CI:DOCS] hack/bats: various improvements
This commit is contained in:
OpenShift Merge Robot
2023-01-04 22:47:43 -05:00
committed by GitHub

View File

@ -12,6 +12,7 @@ $0 is a wrapper for invoking podman system tests.
--root Run only as root --root Run only as root
--rootless Run only as user (i.e. you) --rootless Run only as user (i.e. you)
--remote Run with podman-remote (see below)
FILENAME-PATTERN Run only test files that match 'test/system/*name*', FILENAME-PATTERN Run only test files that match 'test/system/*name*',
e.g. '500' or 'net' will match 500-networking.bats. e.g. '500' or 'net' will match 500-networking.bats.
@ -28,23 +29,27 @@ $0 is a wrapper for invoking podman system tests.
By default, tests ./bin/podman. To test a different podman, do: By default, tests ./bin/podman. To test a different podman, do:
\$ PODMAN=/abs/path/to/podman $0 .... \$ env PODMAN=/abs/path/to/podman $0 ....
To test podman-remote, start your own servers (root and rootless) via: To test podman-remote, start your own servers (root and rootless) via:
/path/to/podman system service --timeout=0 \$ bin/podman system service --timeout=0 &
\$ sudo !!
...then invoke this script with PODMAN=\$(pwd)/bin/podman-remote ...then invoke this script with --remote. (This script can't start the
servers, because we can sudo *starting* the service but can't sudo
(You'd think Ed could be bothered to do all that in this script; but then stopping it: by the time the bats tests finish, the sudo timeout will
the flow would be 'sudo start-service; sudo run-bats; sudo stop-service' have expired. We apologize for the inconvenience.)
and by the time we get to stop-service, the sudo timeout will have lapsed,
and the script will be hanging at the password prompt, and you, who left
your desk for coffee or a walk and expected to come back to completed
root and rootless tests, will be irked because only root tests ran and
now you have to wait for rootless).
$0 also passes through \$OCI_RUNTIME, should you need to test that. $0 also passes through \$OCI_RUNTIME, should you need to test that.
Examples:
\$ $0 220:\"restart cleans up\"
... only the \"restart cleans up\" test in 220-healthcheck.bats
\$ $0 --root 160:\"ps -f\"
... runs all tests in 160-volumes.bats that match \"ps -f\" (root only)
" "
# END usage message # END usage message
@ -63,8 +68,8 @@ chcon -t container_runtime_exec_t $PODMAN
TESTS=test/system TESTS=test/system
REMOTE= REMOTE=
ROOT_ONLY= TEST_ROOT=1
ROOTLESS_ONLY= TEST_ROOTLESS=1
declare -a bats_opts=() declare -a bats_opts=()
@ -74,9 +79,9 @@ for i;do
value=`expr "$i" : '[^=]*=\(.*\)'` value=`expr "$i" : '[^=]*=\(.*\)'`
case "$i" in case "$i" in
-h|--help) echo "$usage"; exit 0;; -h|--help) echo "$usage"; exit 0;;
--root) ROOT_ONLY=1 ;; --root) TEST_ROOTLESS= ;;
--rootless) ROOTLESS_ONLY=1 ;; --rootless) TEST_ROOT= ;;
--remote) REMOTE=remote; echo "--remote is TBI"; exit 1;; --remote) REMOTE=remote ;;
--ts|-T) bats_opts+=("-T") ;; --ts|-T) bats_opts+=("-T") ;;
*/*.bats) TESTS=$i ;; */*.bats) TESTS=$i ;;
*) *)
@ -92,6 +97,20 @@ for i;do
esac esac
done done
# With --remote, use correct binary and make sure daem--I mean server--is live
if [[ "$REMOTE" ]]; then
if ! [[ $PODMAN =~ -remote ]]; then
PODMAN=${PODMAN}-remote
fi
if [[ -n "$TEST_ROOT" ]]; then
sudo $PODMAN info >/dev/null || exit 1
fi
if [[ -n "$TEST_ROOTLESS" ]]; then
$PODMAN info >/dev/null || exit 1
fi
fi
# END initialization and command-line arg checking # END initialization and command-line arg checking
############################################################################### ###############################################################################
@ -106,7 +125,7 @@ fi
export PODMAN_ROOTLESS_USER=$(id -un) export PODMAN_ROOTLESS_USER=$(id -un)
# Root # Root
if [ -z "$ROOTLESS_ONLY" ]; then if [[ "$TEST_ROOT" ]]; then
echo "# bats ${bats_filter[*]} $TESTS" echo "# bats ${bats_filter[*]} $TESTS"
sudo --preserve-env=PODMAN \ sudo --preserve-env=PODMAN \
--preserve-env=QUADLET \ --preserve-env=QUADLET \
@ -119,7 +138,7 @@ if [ -z "$ROOTLESS_ONLY" ]; then
fi fi
# Rootless. (Only if we're not already root) # Rootless. (Only if we're not already root)
if [[ -z "$ROOT_ONLY" && "$(id -u)" != 0 ]]; then if [[ "$TEST_ROOTLESS" && "$(id -u)" != 0 ]]; then
echo "--------------------------------------------------" echo "--------------------------------------------------"
echo "\$ bats ${bats_filter[*]} $TESTS" echo "\$ bats ${bats_filter[*]} $TESTS"
bats "${bats_opts[@]}" "${bats_filter[@]}" $TESTS bats "${bats_opts[@]}" "${bats_filter[@]}" $TESTS