test/system: speed up podman ps --external

The buildah buil kill trick is bad as we have to sleep and wait to aboid
flakes which takes time. Instead it is possible to redo this build part
manually with buildah commands. It is not trival and harder to
understand but it safes 2-3s so I think it is worth it.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger 2024-06-03 19:05:36 +02:00
parent 8fa1ffbbec
commit 350dfabf66
No known key found for this signature in database
GPG Key ID: EB145DD938A3CAF2
1 changed files with 25 additions and 12 deletions

View File

@ -142,25 +142,38 @@ load helpers
run_podman ps --external run_podman ps --external
is "${#lines[@]}" "1" "setup check: no storage containers at start of test" is "${#lines[@]}" "1" "setup check: no storage containers at start of test"
# Force a buildah timeout; this leaves a buildah container behind # Ok this here is basically a way to reproduce a "leaked" podman build buildah
local t0=$SECONDS # container without having to kill any process and usage of sleep.
PODMAN_TIMEOUT=5 run_podman 124 build -t thiswillneverexist - <<EOF run buildah from $IMAGE
FROM $IMAGE assert "$status" -eq 0 "buildah from successfully"
RUN touch /intermediate.image.to.be.pruned buildah_cid="$output"
RUN sleep 30
EOF # Commit new image so we have something to prune.
local t1=$SECONDS run buildah commit $buildah_cid
local delta_t=$((t1 - t0)) assert "$status" -eq 0 "buildah commit successfully"
assert $delta_t -le 10 \ buildah_image_id="${lines[-1]}"
"podman build did not get killed within 10 seconds"
# Create new buildah container with new image so that one can be pruned directly.
run buildah from "$buildah_image_id"
assert "$status" -eq 0 "buildah from new buildah image successfully"
# We have to mount the container to trigger the "container .* is mounted" check below.
local unshare=
if is_rootless; then
# rootless needs unshare for mounting
unshare="buildah unshare"
fi
run $unshare buildah mount "$buildah_cid"
assert "$status" -eq 0 "buildah mount container successfully"
run_podman ps -a run_podman ps -a
is "${#lines[@]}" "1" "podman ps -a does not see buildah containers" is "${#lines[@]}" "1" "podman ps -a does not see buildah containers"
run_podman ps --external run_podman ps --external
is "${#lines[@]}" "3" "podman ps -a --external sees buildah containers" is "${#lines[@]}" "3" "podman ps -a --external sees buildah containers"
# output can include "second ago" or "seconds ago" depending on the timing so match both
is "${lines[1]}" \ is "${lines[1]}" \
"[0-9a-f]\{12\} \+$IMAGE *buildah .* seconds ago .* Storage .* ${PODMAN_TEST_IMAGE_NAME}-working-container" \ "[0-9a-f]\{12\} \+$IMAGE *buildah .* seconds\? ago .* Storage .* ${PODMAN_TEST_IMAGE_NAME}-working-container" \
"podman ps --external" "podman ps --external"
# 'rm -a' should be a NOP # 'rm -a' should be a NOP