mirror of
https://github.com/containers/podman.git
synced 2025-06-30 15:49:03 +08:00
test/system: simplify test signal handling in containers
The current logic used podman logs I don't understand way, all we care about is the container output and we can just read the same with a attached podman run, of course we have to move it into the background but it did the some with logs. This also allows us to remove the extra log-driver checks and because podman logs seems to be much slower than the extra run we safe over 10s with this change. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
@ -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" {
|
||||||
|
Reference in New Issue
Block a user