Skip to content

Commit

Permalink
test/system: Add test for journald log check in quadlet
Browse files Browse the repository at this point in the history
This test is used to ensure the default configuration for quadlets
generated service files is sending stdout/stderr/syslog to the
journald.

Signed-off-by: Yiqiao Pu <ypu@redhat.com>
  • Loading branch information
ypu committed May 29, 2024
1 parent d1dd720 commit ad60988
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions test/system/252-quadlet.bats
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,39 @@ function remove_secret() {
run_podman secret rm $secret_name
}

function wait_for_journal() {
local step=1
local count=10
local expect_str=

while [ "$#" -gt 0 ]; do
case "$1" in
-s|--step)
step="$2"
shift 2
;;
-c|--count)
count="$2"
shift 2
;;
*)
expect_str="$1"
shift 1
;;
esac
done

while [ "$count" -gt 0 ]; do
run journalctl "--since=$STARTED_TIME" --unit="$QUADLET_SERVICE_NAME"
if [[ "$output" =~ "$expect_str" ]]; then
return
fi
sleep "$step"
count=$(( count - 1 ))
done
die "Wait for $expect_str shows up in journalctl output timeout"
}

@test "quadlet - basic" {
# Network=none is to work around a Pasta bug, can be removed once a patched Pasta is available.
# Ref https://github.com/containers/podman/pull/21563#issuecomment-1965145324
Expand Down Expand Up @@ -1542,4 +1575,30 @@ EOF
service_cleanup $QUADLET_SERVICE_NAME inactive
run_podman rmi $untagged_image:latest $built_image $(pause_image)
}

@test "quadlet - output and error message" {
local quadlet_file=$PODMAN_TMPDIR/basic_$(random_string).container
cat > $quadlet_file <<EOF
[Container]
Image=$IMAGE
Exec=sh -c "echo I AM AN OUTPUT; echo I AM AN ERROR 1>&2; top -d 10"
EOF

run_quadlet "$quadlet_file"
service_setup $QUADLET_SERVICE_NAME

wait_for_journal "Started $QUADLET_SERVICE_NAME"

run journalctl "--since=$STARTED_TIME" --unit="$QUADLET_SERVICE_NAME"
assert "$output" =~ 'I AM AN OUTPUT' "Output can be found with journalctl"
assert "$output" =~ 'I AM AN ERROR' "Error can be found with journalctl"
assert "$output" =~ "Starting $QUADLET_SERVICE_NAME" "Status information can be found with journalctl"

# log priority 3 in journalctl is err. This is documented in syslog(3)
run journalctl "--since=$STARTED_TIME" --priority=3 --unit="$QUADLET_SERVICE_NAME"
assert "$output" =~ 'I AM AN ERROR' "Error can be found with journalctl --priority=3"
assert "$output" != .*"I AM AN OUTPUT".* "Output can not be found with journalctl --priority=3"

service_cleanup $QUADLET_SERVICE_NAME failed
}
# vim: filetype=sh

0 comments on commit ad60988

Please sign in to comment.