Skip to content

Commit

Permalink
system tests: avoid rmi -a ... plus cleanup
Browse files Browse the repository at this point in the history
I noticed 'rmi -a' in a test. I tried to fix it. Hilarity ensued.

'rmi -a' is evil: it forces a fresh pull of our test image,
which in turn almost guarantees a flake some day. We avoid
it, but once in a while it slips in.

While fixing it, I noticed a bevy of other problems that
needed cleanup.

Signed-off-by: Ed Santiago <[email protected]>
  • Loading branch information
edsantiago committed Jun 15, 2022
1 parent 3109534 commit c6b9baa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion test/system/070-build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ EOF
is "$output" "[no instance of 'Using cache']" "no cache used"
fi

run_podman rmi -a --force
run_podman rmi -f build_test
}

# Caveat lector: this test was mostly copy-pasted from buildah in #9275.
Expand Down
33 changes: 23 additions & 10 deletions test/system/250-systemd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ function teardown() {
rm -f "$UNIT_FILE"
systemctl daemon-reload
fi
run_podman rmi -a

basic_teardown
}
Expand All @@ -53,10 +52,17 @@ function service_setup() {

# Helper to stop a systemd service running a container
function service_cleanup() {
local status=$1
run systemctl stop "$SERVICE_NAME"
assert $status -eq 0 "Error stopping systemd unit $SERVICE_NAME: $output"

# Regression test for #11304: confirm that unit stops into correct state
local expected_state="$1"
if [[ -n "$expected_state" ]]; then
run systemctl show --property=ActiveState "$SERVICE_NAME"
assert "$output" = "ActiveState=$expected_state" \
"state of service after systemctl stop"
fi

run systemctl disable "$SERVICE_NAME"
assert $status -eq 0 "Error disabling systemd unit $SERVICE_NAME: $output"

Expand Down Expand Up @@ -88,26 +94,28 @@ function service_cleanup() {
@test "podman autoupdate local" {
# Note that the entrypoint may be a JSON string which requires preserving the quotes (see #12477)
cname=$(random_string)
run_podman create --name $cname --label "io.containers.autoupdate=local" --entrypoint '["top"]' $IMAGE

# Create a scratch image (copy of our regular one)
image_copy=base$(random_string | tr A-Z a-z)
run_podman tag $IMAGE $image_copy

# Create a container based on that
run_podman create --name $cname --label "io.containers.autoupdate=local" --entrypoint '["top"]' $image_copy

# Start systemd service to run this container
service_setup

# Give container time to start; make sure output looks top-like
sleep 2
run_podman logs $cname
is "$output" ".*Load average:.*" "running container 'top'-like output"

# Save the container id before updating
run_podman ps --format '{{.ID}}'
wait_for_output 'Load average' $cname

# Run auto-update and check that it restarted the container
run_podman commit --change "CMD=/bin/bash" $cname $IMAGE
run_podman commit --change "CMD=/bin/bash" $cname $image_copy
run_podman auto-update
is "$output" ".*$SERVICE_NAME.*" "autoupdate local restarted container"

# All good. Stop service, clean up.
service_cleanup
run_podman rmi $image_copy
}

# These tests can fail in dev. environment because of SELinux.
Expand Down Expand Up @@ -235,6 +243,7 @@ LISTEN_FDNAMES=listen_fdnames" | sort)

run_podman rm -f $cname
run_podman pod rm -f $podname
run_podman rmi $(pause_image)
}

@test "podman generate - systemd template only used on --new" {
Expand Down Expand Up @@ -295,6 +304,8 @@ LISTEN_FDNAMES=listen_fdnames" | sort)
unit_file="contrib/systemd/system/${unit_name}"
if [[ -e ${unit_file}.in ]]; then
echo "# [Building & using $unit_name from source]" >&3
# Force regenerating unit file (existing one may have /usr/bin path)
rm -f $unit_file
BINDIR=$(dirname $PODMAN) make $unit_file
cp $unit_file $UNIT_DIR/$unit_name
fi
Expand Down Expand Up @@ -360,6 +371,8 @@ EOF
systemctl stop $service_name
run_podman 1 container exists $service_container
run_podman 1 pod exists test_pod
run_podman rmi $(pause_image)
rm -f $UNIT_DIR/$unit_name
}

@test "podman-system-service containers survive service stop" {
Expand Down

0 comments on commit c6b9baa

Please sign in to comment.