From 1a2e54ce65870e29335a578789f757e1561d839a Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Wed, 4 Jan 2023 13:40:41 -0700 Subject: [PATCH 1/3] hack/bats: fix root/rootless logic The ROOT{,LESS}_ONLY logic is confusing and unmaintainable. Change it to an easier-to-read positive check. Signed-off-by: Ed Santiago --- hack/bats | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hack/bats b/hack/bats index dec70f1eaa..fe48fb73cb 100755 --- a/hack/bats +++ b/hack/bats @@ -63,8 +63,8 @@ chcon -t container_runtime_exec_t $PODMAN TESTS=test/system REMOTE= -ROOT_ONLY= -ROOTLESS_ONLY= +TEST_ROOT=1 +TEST_ROOTLESS=1 declare -a bats_opts=() @@ -74,8 +74,8 @@ for i;do value=`expr "$i" : '[^=]*=\(.*\)'` case "$i" in -h|--help) echo "$usage"; exit 0;; - --root) ROOT_ONLY=1 ;; - --rootless) ROOTLESS_ONLY=1 ;; + --root) TEST_ROOTLESS= ;; + --rootless) TEST_ROOT= ;; --remote) REMOTE=remote; echo "--remote is TBI"; exit 1;; --ts|-T) bats_opts+=("-T") ;; */*.bats) TESTS=$i ;; @@ -106,7 +106,7 @@ fi export PODMAN_ROOTLESS_USER=$(id -un) # Root -if [ -z "$ROOTLESS_ONLY" ]; then +if [[ "$TEST_ROOT" ]]; then echo "# bats ${bats_filter[*]} $TESTS" sudo --preserve-env=PODMAN \ --preserve-env=QUADLET \ @@ -119,7 +119,7 @@ if [ -z "$ROOTLESS_ONLY" ]; then fi # 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 "\$ bats ${bats_filter[*]} $TESTS" bats "${bats_opts[@]}" "${bats_filter[@]}" $TESTS From d7ac11005c7ba9c3827a2f0e80466487a8db939e Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Wed, 4 Jan 2023 11:31:31 -0700 Subject: [PATCH 2/3] hack/bats: add --remote option Even though we still rely on the user to start the podman system service, enable the option anyway. It's much, much friendlier than requiring 'env PODMAN=etc-etc'. Signed-off-by: Ed Santiago --- hack/bats | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/hack/bats b/hack/bats index fe48fb73cb..8aab4bd734 100755 --- a/hack/bats +++ b/hack/bats @@ -12,6 +12,7 @@ $0 is a wrapper for invoking podman system tests. --root Run only as root --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*', e.g. '500' or 'net' will match 500-networking.bats. @@ -32,17 +33,14 @@ By default, tests ./bin/podman. To test a different podman, do: 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. - (You'd think Ed could be bothered to do all that in this script; but then - the flow would be 'sudo start-service; sudo run-bats; sudo stop-service' - 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). + (This script cannot start the servers, because we can sudo *starting* + the service but can't sudo stopping it: by the time the bats tests + finish, the sudo timeout will have expired.) $0 also passes through \$OCI_RUNTIME, should you need to test that. " @@ -76,7 +74,7 @@ for i;do -h|--help) echo "$usage"; exit 0;; --root) TEST_ROOTLESS= ;; --rootless) TEST_ROOT= ;; - --remote) REMOTE=remote; echo "--remote is TBI"; exit 1;; + --remote) REMOTE=remote ;; --ts|-T) bats_opts+=("-T") ;; */*.bats) TESTS=$i ;; *) @@ -92,6 +90,20 @@ for i;do esac 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 ############################################################################### From 710eeb34038c051badc4b7b2fc801d94cb51052e Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Wed, 4 Jan 2023 14:01:52 -0700 Subject: [PATCH 3/3] hack/bats: improve usage message Signed-off-by: Ed Santiago --- hack/bats | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hack/bats b/hack/bats index 8aab4bd734..fb99181f52 100755 --- a/hack/bats +++ b/hack/bats @@ -29,20 +29,27 @@ $0 is a wrapper for invoking podman system tests. 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: \$ bin/podman system service --timeout=0 & \$ sudo !! -...then invoke this script with --remote. - - (This script cannot start the servers, because we can sudo *starting* - the service but can't sudo stopping it: by the time the bats tests - finish, the sudo timeout will have expired.) +...then invoke this script with --remote. (This script can't start the +servers, because we can sudo *starting* the service but can't sudo +stopping it: by the time the bats tests finish, the sudo timeout will +have expired. We apologize for the inconvenience.) $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