systests: quadlet: fixes for RHEL8

Some quadlet tests are failing on RHEL8: test code was
using journalctl to check output from containers. This
fails on RHEL8, where default log driver is k8s-file.

Solution: use 'podman logs' instead. To do so, we need to
keep the containers alive (otherwise, quadlet seems to
delete them on exit). Do so by running 'top -b' (batch);
the currently-used 'top' was failing because not-a-tty.

Signed-off-by: Ed Santiago <santiago@redhat.com>
This commit is contained in:
Ed Santiago
2023-07-18 12:35:05 -06:00
parent a977c8281e
commit 558a70262d

View File

@ -16,7 +16,7 @@ function start_time() {
function setup() { function setup() {
skip_if_remote "quadlet tests are meaningless over remote" skip_if_remote "quadlet tests are meaningless over remote"
skip_if_rootless_cgroupsv1 "Can't use --cgroups=split w/ CGv1 (issue 17456, wontfix)" skip_if_rootless_cgroupsv1 "Can't use --cgroups=split w/ CGv1 (issue 17456, wontfix)"
skip_if_journald_unavailable "quadlet isn't really usable without journal" skip_if_journald_unavailable "Needed for RHEL. FIXME: we might be able to reenable a subset of tests."
test -x "$QUADLET" || die "Cannot run quadlet tests without executable \$QUADLET ($QUADLET)" test -x "$QUADLET" || die "Cannot run quadlet tests without executable \$QUADLET ($QUADLET)"
@ -640,16 +640,14 @@ EOF
cat > $quadlet_file <<EOF cat > $quadlet_file <<EOF
[Container] [Container]
Rootfs=/:O Rootfs=/:O
Exec=sh -c "echo STARTED CONTAINER; echo "READY=1" | socat -u STDIN unix-sendto:\$NOTIFY_SOCKET; top" Exec=sh -c "echo STARTED CONTAINER; echo "READY=1" | socat -u STDIN unix-sendto:\$NOTIFY_SOCKET; top -b"
Notify=yes Notify=yes
EOF EOF
run_quadlet "$quadlet_file" run_quadlet "$quadlet_file"
service_setup $QUADLET_SERVICE_NAME service_setup $QUADLET_SERVICE_NAME
# Ensure we have output. Output is synced via sd-notify (socat in Exec) wait_for_output "STARTED CONTAINER" $QUADLET_CONTAINER_NAME
run journalctl "--since=$STARTED_TIME" --unit="$QUADLET_SERVICE_NAME"
is "$output" '.*STARTED CONTAINER.*'
} }
@test "quadlet - selinux disable" { @test "quadlet - selinux disable" {
@ -659,15 +657,14 @@ EOF
[Container] [Container]
Image=$IMAGE Image=$IMAGE
SecurityLabelDisable=true SecurityLabelDisable=true
Exec=sh -c "echo STARTED CONTAINER; top" Exec=sh -c "echo STARTED CONTAINER; top -b"
EOF EOF
run_quadlet "$quadlet_file" run_quadlet "$quadlet_file"
service_setup $QUADLET_SERVICE_NAME service_setup $QUADLET_SERVICE_NAME
# Ensure we have output. Output is synced via sd-notify (socat in Exec) # Ensure we have output. Output is synced via sd-notify (socat in Exec)
run journalctl "--since=$STARTED_TIME" --unit="$QUADLET_SERVICE_NAME" wait_for_output "STARTED CONTAINER" $QUADLET_CONTAINER_NAME
is "$output" '.*STARTED CONTAINER.*'
run_podman container inspect --format "{{.ProcessLabel}}" $QUADLET_CONTAINER_NAME run_podman container inspect --format "{{.ProcessLabel}}" $QUADLET_CONTAINER_NAME
is "$output" "" "container should be started without specifying a Process Label" is "$output" "" "container should be started without specifying a Process Label"
@ -686,15 +683,14 @@ Image=$IMAGE
SecurityLabelType=spc_t SecurityLabelType=spc_t
SecurityLabelLevel=s0:c100,c200 SecurityLabelLevel=s0:c100,c200
SecurityLabelFileType=container_ro_file_t SecurityLabelFileType=container_ro_file_t
Exec=sh -c "echo STARTED CONTAINER; top" Exec=sh -c "echo STARTED CONTAINER; top -b"
EOF EOF
run_quadlet "$quadlet_file" run_quadlet "$quadlet_file"
service_setup $QUADLET_SERVICE_NAME service_setup $QUADLET_SERVICE_NAME
# Ensure we have output. Output is synced via sd-notify (socat in Exec) # Ensure we have output. Output is synced via sd-notify (socat in Exec)
run journalctl "--since=$STARTED_TIME" --unit="$QUADLET_SERVICE_NAME" wait_for_output "STARTED CONTAINER" $NAME
is "$output" '.*STARTED CONTAINER.*'
run_podman container ps run_podman container ps
run_podman container inspect --format "{{.ProcessLabel}}" $NAME run_podman container inspect --format "{{.ProcessLabel}}" $NAME
@ -714,7 +710,7 @@ EOF
ContainerName=$NAME ContainerName=$NAME
Image=$IMAGE Image=$IMAGE
Secret=$SECRET_NAME,type=env,target=MYSECRET Secret=$SECRET_NAME,type=env,target=MYSECRET
Exec=sh -c "echo STARTED CONTAINER; echo "READY=1" | socat -u STDIN unix-sendto:\$NOTIFY_SOCKET; top" Exec=sh -c "echo STARTED CONTAINER; echo "READY=1" | socat -u STDIN unix-sendto:\$NOTIFY_SOCKET; top -b"
Notify=yes Notify=yes
EOF EOF
@ -722,8 +718,7 @@ EOF
service_setup $QUADLET_SERVICE_NAME service_setup $QUADLET_SERVICE_NAME
# Ensure we have output. Output is synced via sd-notify (socat in Exec) # Ensure we have output. Output is synced via sd-notify (socat in Exec)
run journalctl "--since=$STARTED_TIME" --unit="$QUADLET_SERVICE_NAME" wait_for_output "STARTED CONTAINER" $QUADLET_CONTAINER_NAME
is "$output" '.*STARTED CONTAINER.*'
run_podman exec $QUADLET_CONTAINER_NAME /bin/sh -c "printenv MYSECRET" run_podman exec $QUADLET_CONTAINER_NAME /bin/sh -c "printenv MYSECRET"
is "$output" $SECRET is "$output" $SECRET
@ -741,7 +736,7 @@ EOF
ContainerName=$NAME ContainerName=$NAME
Image=$IMAGE Image=$IMAGE
Secret=$SECRET_NAME,type=mount,target=/root/secret Secret=$SECRET_NAME,type=mount,target=/root/secret
Exec=sh -c "echo STARTED CONTAINER; echo "READY=1" | socat -u STDIN unix-sendto:\$NOTIFY_SOCKET; top" Exec=sh -c "echo STARTED CONTAINER; echo "READY=1" | socat -u STDIN unix-sendto:\$NOTIFY_SOCKET; top -b"
Notify=yes Notify=yes
EOF EOF
@ -749,8 +744,7 @@ EOF
service_setup $QUADLET_SERVICE_NAME service_setup $QUADLET_SERVICE_NAME
# Ensure we have output. Output is synced via sd-notify (socat in Exec) # Ensure we have output. Output is synced via sd-notify (socat in Exec)
run journalctl "--since=$STARTED_TIME" --unit="$QUADLET_SERVICE_NAME" wait_for_output "STARTED CONTAINER" $QUADLET_CONTAINER_NAME
is "$output" '.*STARTED CONTAINER.*'
run_podman exec $QUADLET_CONTAINER_NAME /bin/sh -c "cat /root/secret" run_podman exec $QUADLET_CONTAINER_NAME /bin/sh -c "cat /root/secret"
is "$output" $SECRET is "$output" $SECRET