Merge pull request #22826 from Luap99/fast-system-test-2

test/system: make some tests faster part 2
This commit is contained in:
openshift-merge-bot[bot] 2024-05-29 12:59:09 +00:00 committed by GitHub
commit 846d717c0b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 50 additions and 78 deletions

View File

@ -127,10 +127,7 @@ echo $rand | 0 | $rand
@test "podman run --name" { @test "podman run --name" {
randomname=$(random_string 30) randomname=$(random_string 30)
# Assume that 4 seconds gives us enough time for 3 quick tests (or at run_podman run -d --name $randomname $IMAGE sleep inf
# least for the 'ps'; the 'container exists' should pass even in the
# unlikely case that the container exits before we get to them)
run_podman run -d --name $randomname $IMAGE sleep 4
cid=$output cid=$output
run_podman ps --format '{{.Names}}--{{.ID}}' run_podman ps --format '{{.Names}}--{{.ID}}'
@ -140,7 +137,7 @@ echo $rand | 0 | $rand
run_podman container exists $cid run_podman container exists $cid
# Done with live-container tests; now let's test after container finishes # Done with live-container tests; now let's test after container finishes
run_podman wait $cid run_podman stop -t0 $cid
# Container still exists even after stopping: # Container still exists even after stopping:
run_podman container exists $randomname run_podman container exists $randomname
@ -1143,16 +1140,19 @@ EOF
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman 1 run --rm $IMAGE touch /testro CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman 1 run --rm $IMAGE touch /testro
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only=false $IMAGE touch /testrw CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only=false $IMAGE touch /testrw
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm $IMAGE touch /tmp/testrw
for dir in /tmp /var/tmp /dev /dev/shm /run; do
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm $IMAGE touch $dir/testro
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only=false $IMAGE touch $dir/testro
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only=false --read-only-tmpfs=true $IMAGE touch $dir/testro
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only-tmpfs=true $IMAGE touch $dir/testro
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman 1 run --rm --read-only-tmpfs=false $IMAGE touch $dir/testro files="/tmp/a /var/tmp/b /dev/c /dev/shm/d /run/e"
assert "$output" =~ "touch: $dir/testro: Read-only file system" CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm $IMAGE touch $files
done CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only=false $IMAGE touch $files
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only=false --read-only-tmpfs=true $IMAGE touch $files
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman run --rm --read-only-tmpfs=true $IMAGE touch $files
CONTAINERS_CONF_OVERRIDE="$containersconf" run_podman 1 run --rm --read-only-tmpfs=false $IMAGE touch $files
assert "$output" == "touch: /tmp/a: Read-only file system
touch: /var/tmp/b: Read-only file system
touch: /dev/c: Read-only file system
touch: /dev/shm/d: Read-only file system
touch: /run/e: Read-only file system"
} }
@test "podman run ulimit from containers.conf" { @test "podman run ulimit from containers.conf" {

View File

@ -89,36 +89,30 @@ function _log_test_multi() {
skip_if_remote "logs does not support multiple containers when run remotely" skip_if_remote "logs does not support multiple containers when run remotely"
# Under k8s file, 'podman logs' returns just the facts, Ma'am.
# Under journald, there may be other cruft (e.g. container removals)
local etc=
if [[ $driver =~ journal ]]; then
etc='.*'
fi
local events_backend=$(_additional_events_backend $driver) local events_backend=$(_additional_events_backend $driver)
# Simple helper to make the container starts, below, easier to read # Simple helper to make the container starts, below, easier to read
local -a cid local -a cid
doit() { doit() {
run_podman ${events_backend} run --log-driver=$driver --rm -d --name "$1" $IMAGE sh -c "$2"; run_podman ${events_backend} run --log-driver=$driver -d \
--name "$1" $IMAGE sh -c "$2";
cid+=($(echo "${output:0:12}")) cid+=($(echo "${output:0:12}"))
} }
# Not really a guarantee that we'll get a-b-c-d in order, but it's doit c1 "echo a1; echo a2"
# the best we can do. The trailing 'sleep' in each container doit c2 "echo b1; echo b2"
# minimizes the chance of a race condition in which the container
# is removed before 'podman logs' has a chance to wake up and read
# the final output.
doit c1 "echo a;sleep 10;echo d;sleep 3"
doit c2 "sleep 1;echo b;sleep 2;echo c;sleep 3"
# Reading logs only guarantees the order for a single container,
# when using multiple containers the line order between them can vary.
run_podman ${events_backend} logs -f c1 c2 run_podman ${events_backend} logs -f c1 c2
assert "$output" =~ \ assert "$output" =~ \
"${cid[0]} a$etc ".*^${cid[0]} a1\$.*
${cid[1]} b$etc ${cid[0]} a2" "Sequential output from c1"
${cid[1]} c$etc assert "$output" =~ \
${cid[0]} d" "Sequential output from logs" ".*^${cid[1]} b1\$.*
${cid[1]} b2" "Sequential output from c2"
run_podman rm -f -t0 ${cid[0]} ${cid[1]}
} }
@test "podman logs - multi k8s-file" { @test "podman logs - multi k8s-file" {

View File

@ -24,8 +24,8 @@ load helpers
"${cid:0:12} \+$IMAGE \+sleep [0-9]\+ .*second.* $cname"\ "${cid:0:12} \+$IMAGE \+sleep [0-9]\+ .*second.* $cname"\
"output from podman ps" "output from podman ps"
# OK. Wait for sleep to finish... # OK. Stop container now.
run_podman wait $cid run_podman stop -t0 $cid
# ...then make sure container shows up as stopped # ...then make sure container shows up as stopped
run_podman ps -a run_podman ps -a

View File

@ -124,10 +124,10 @@ function __run_healthcheck_container() {
run_podman run -d --name $1 \ run_podman run -d --name $1 \
--health-cmd /bin/false \ --health-cmd /bin/false \
--health-interval 1s \ --health-interval 1s \
--health-retries 2 \ --health-retries 1 \
--health-timeout 1s \ --health-timeout 1s \
--health-on-failure=stop \ --health-on-failure=stop \
--stop-timeout=2 \ --stop-timeout=1 \
--health-start-period 0 \ --health-start-period 0 \
--stop-signal SIGTERM \ --stop-signal SIGTERM \
$IMAGE sleep infinity $IMAGE sleep infinity
@ -156,7 +156,7 @@ function __run_healthcheck_container() {
assert "$output" =~ "Error: cannot remove container $cid as it is .* - running or paused containers cannot be removed without force: container state improper" \ assert "$output" =~ "Error: cannot remove container $cid as it is .* - running or paused containers cannot be removed without force: container state improper" \
"Expected error message from podman rm" "Expected error message from podman rm"
rm_failures=$((rm_failures + 1)) rm_failures=$((rm_failures + 1))
sleep 1 sleep 0.5
done done
# At this point, container should be gone # At this point, container should be gone

View File

@ -7,35 +7,18 @@ load helpers
# bats test_tags=distro-integration # bats test_tags=distro-integration
@test "podman kill - test signal handling in containers" { @test "podman kill - test signal handling in containers" {
local cname=c-$(random_string 10)
# Prepare for 'logs -f' local fifo=${PODMAN_TMPDIR}/podman-kill-fifo.$(random_string 10)
run_podman info --format '{{.Host.LogDriver}}' mkfifo $fifo
log_driver=$output
run_podman info --format '{{.Host.EventLogger}}'
event_logger=$output
opt_log_driver=
if [ $log_driver = "journald" ] && [ $event_logger != "journald" ]; then
# Since PR#10431, 'logs -f' with journald driver is only supported with journald events backend.
# Set '--log driver' temporally because remote doesn't support '--events-backend'.
opt_log_driver="--log-driver k8s-file"
fi
# Start a container that will handle all signals by emitting 'got: N' # Start a container that will handle all signals by emitting 'got: N'
local -a signals=(1 2 3 4 5 6 8 10 12 13 14 15 16 20 21 22 23 24 25 26 64) local -a signals=(1 2 3 4 5 6 8 10 12 13 14 15 16 20 21 22 23 24 25 26 64)
run_podman run -d ${opt_log_driver} $IMAGE sh -c \ $PODMAN run --name $cname $IMAGE sh -c \
"for i in ${signals[*]}; do trap \"echo got: \$i\" \$i; done; "for i in ${signals[*]}; do trap \"echo got: \$i\" \$i; done;
echo READY; echo READY;
while ! test -e /stop; do sleep 0.1; done; while ! test -e /stop; do sleep 0.1; done;
echo DONE" echo DONE" &>$fifo </dev/null &
cid="$output" podman_run_pid=$!
# Run 'logs -f' on that container, but run it in the background with
# redirection to a named pipe from which we (foreground job) read
# and confirm that signals are received. We can't use run_podman here.
local fifo=${PODMAN_TMPDIR}/podman-kill-fifo.$(random_string 10)
mkfifo $fifo
$PODMAN logs -f $cid >$fifo </dev/null &
podman_log_pid=$!
# Open the FIFO for reading, and keep it open. This prevents a race # Open the FIFO for reading, and keep it open. This prevents a race
# condition in which the container can exit (e.g. if for some reason # condition in which the container can exit (e.g. if for some reason
@ -54,7 +37,7 @@ load helpers
local signal=$1 local signal=$1
local signum=${2:-$1} # e.g. if signal=HUP, we expect to see '1' local signum=${2:-$1} # e.g. if signal=HUP, we expect to see '1'
run_podman kill -s $signal $cid run_podman kill -s $signal $cname
read -t 60 -u 5 actual || die "Timed out: no ACK for kill -s $signal" read -t 60 -u 5 actual || die "Timed out: no ACK for kill -s $signal"
is "$actual" "got: $signum" "Signal $signal handled by container" is "$actual" "got: $signum" "Signal $signal handled by container"
} }
@ -74,14 +57,13 @@ load helpers
# Done. Tell the container to stop, and wait for final DONE. # Done. Tell the container to stop, and wait for final DONE.
# The '-d' is because container exit is racy: the exec process itself # The '-d' is because container exit is racy: the exec process itself
# could get caught and killed by cleanup, causing this step to exit 137 # could get caught and killed by cleanup, causing this step to exit 137
run_podman exec -d $cid touch /stop run_podman exec -d $cname touch /stop
read -t 5 -u 5 done || die "Timed out waiting for DONE from container" read -t 5 -u 5 done || die "Timed out waiting for DONE from container"
is "$done" "DONE" "final log message from container" is "$done" "DONE" "final log message from container"
# Clean up # Clean up
run_podman wait $cid run_podman rm -f -t0 $cname
run_podman rm $cid wait $podman_run_pid || die "wait for podman run failed"
wait $podman_log_pid
} }
@test "podman kill - rejects invalid args" { @test "podman kill - rejects invalid args" {

View File

@ -213,8 +213,8 @@ function check_shell_completion() {
i=$(($i + 1)) i=$(($i + 1))
# If the argument ends with ...] than we accept 0...n args # If the argument ends with ...] than we accept 0...n args
# Loop three times to make sure we are not only completing the first arg # Loop two times to make sure we are not only completing the first arg
if [[ ! ${arg} =~ "..." ]] || [[ i -gt 3 ]]; then if [[ ! ${arg} =~ "..." ]] || [[ i -gt 1 ]]; then
break break
fi fi

View File

@ -31,8 +31,7 @@ metadata:
spec: spec:
containers: containers:
- command: - command:
- sleep - /home/podman/pause
- \"100\"
env: env:
- name: PATH - name: PATH
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
@ -811,15 +810,12 @@ EOF
} }
@test "podman kube generate tmpfs on /tmp" { @test "podman kube generate tmpfs on /tmp" {
KUBE=$PODMAN_TMPDIR/kube.yaml local yaml=$PODMAN_TMPDIR/test.yaml
run_podman create --name test $IMAGE sleep 100 _write_test_yaml command=/home/podman/pause
run_podman kube generate test -f $KUBE run_podman kube play $yaml
run_podman kube play $KUBE run_podman exec test_pod-test sh -c "mount | grep /tmp"
run_podman exec test-pod-test sh -c "mount | grep /tmp"
assert "$output" !~ "noexec" "mounts on /tmp should not be noexec" assert "$output" !~ "noexec" "mounts on /tmp should not be noexec"
run_podman kube down $KUBE run_podman kube down $yaml
run_podman pod rm -a -f -t 0
run_podman rm -a -f -t 0
} }
@test "podman kube play - pull policy" { @test "podman kube play - pull policy" {