Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set flags to test 'logs -f' with journald driver #12118

Merged
merged 1 commit into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions test/system/035-logs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ load helpers
run_podman rm $cid
}

function _additional_events_backend() {
local driver=$1
# Since PR#10431, 'logs -f' with journald driver is only supported with journald events backend.
if [[ $driver = "journald" ]]; then
run_podman info --format '{{.Host.EventLogger}}' >/dev/null
if [[ $output != "journald" ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably late-night brain malfunction on my part, but should this be == rather then !=?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think != is correct. When the event logger from containers.conf is NOT journald, I would like to add --events-backend jouranld so that logs -f works.

Thanks.

echo "--events-backend journald"
fi
fi
}

function _log_test_multi() {
local driver=$1

Expand All @@ -42,10 +53,12 @@ function _log_test_multi() {
etc='.*'
fi

local events_backend=$(_additional_events_backend $driver)

# Simple helper to make the container starts, below, easier to read
local -a cid
doit() {
run_podman run --log-driver=$driver --rm -d --name "$1" $IMAGE sh -c "$2";
run_podman ${events_backend} run --log-driver=$driver --rm -d --name "$1" $IMAGE sh -c "$2";
cid+=($(echo "${output:0:12}"))
}

Expand All @@ -57,7 +70,7 @@ function _log_test_multi() {
doit c1 "echo a;sleep 10;echo d;sleep 3"
doit c2 "sleep 1;echo b;sleep 2;echo c;sleep 3"

run_podman logs -f c1 c2
run_podman ${events_backend} logs -f c1 c2
is "$output" \
"${cid[0]} a$etc
${cid[1]} b$etc
Expand Down Expand Up @@ -187,15 +200,20 @@ function _log_test_follow() {
contentA=$(random_string)
contentB=$(random_string)
contentC=$(random_string)
local events_backend=$(_additional_events_backend $driver)

if [[ -n "${events_backend}" ]]; then
skip_if_remote "remote does not support --events-backend"
fi

# Note: it seems we need at least three log lines to hit #11461.
run_podman run --log-driver=$driver --name $cname $IMAGE sh -c "echo $contentA; echo $contentB; echo $contentC"
run_podman logs -f $cname
run_podman ${events_backend} run --log-driver=$driver --name $cname $IMAGE sh -c "echo $contentA; echo $contentB; echo $contentC"
run_podman ${events_backend} logs -f $cname
is "$output" "$contentA
$contentB
$contentC" "logs -f on exitted container works"

run_podman rm -t 0 -f $cname
run_podman ${events_backend} rm -t 0 -f $cname
}

@test "podman logs - --follow k8s-file" {
Expand Down
15 changes: 14 additions & 1 deletion test/system/130-kill.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@
load helpers

@test "podman kill - test signal handling in containers" {

# Prepare for 'logs -f'
run_podman info --format '{{.Host.LogDriver}}'
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'
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 $IMAGE sh -c \
run_podman run -d ${opt_log_driver} $IMAGE sh -c \
"for i in ${signals[*]}; do trap \"echo got: \$i\" \$i; done;
echo READY;
while ! test -e /stop; do sleep 0.05; done;
Expand Down