Skip to content

Commit

Permalink
Merge pull request #22909 from Luap99/fast-system-test-4
Browse files Browse the repository at this point in the history
test/system: speed up basic_{setup,teardown}()
  • Loading branch information
openshift-merge-bot[bot] authored Jun 18, 2024
2 parents afe55cd + 0eaec1a commit b869efa
Show file tree
Hide file tree
Showing 29 changed files with 260 additions and 119 deletions.
2 changes: 1 addition & 1 deletion contrib/cirrus/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ EPOCH_TEST_COMMIT="$CIRRUS_BASE_SHA"
# are consumed by the passthrough_envars() automation library function.
#
# List of envariables which must be EXACT matches
PASSTHROUGH_ENV_EXACT='CGROUP_MANAGER|DEST_BRANCH|DISTRO_NV|GOCACHE|GOPATH|GOSRC|NETWORK_BACKEND|OCI_RUNTIME|PODMAN_IGNORE_CGROUPSV1_WARNING|ROOTLESS_USER|SCRIPT_BASE|SKIP_USERNS|EC2_INST_TYPE|PODMAN_DB|STORAGE_FS'
PASSTHROUGH_ENV_EXACT='CGROUP_MANAGER|DEST_BRANCH|DISTRO_NV|GOCACHE|GOPATH|GOSRC|NETWORK_BACKEND|OCI_RUNTIME|PODMAN_IGNORE_CGROUPSV1_WARNING|ROOTLESS_USER|SCRIPT_BASE|SKIP_USERNS|EC2_INST_TYPE|PODMAN_DB|STORAGE_FS|PODMAN_BATS_LEAK_CHECK'

# List of envariable patterns which must match AT THE BEGINNING of the name.
# Consumed by the passthrough_envars() automation library function.
Expand Down
8 changes: 7 additions & 1 deletion contrib/cirrus/setup_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,13 @@ case "$TEST_FLAVOR" in
int)
showrun make .install.ginkgo
;&
sys) ;&
sys)
# when run nighlty check for system test leaks
# shellcheck disable=SC2154
if [[ "$CIRRUS_CRON" != '' ]]; then
export PODMAN_BATS_LEAK_CHECK=1
fi
;&
upgrade_test) ;&
bud) ;&
bindings) ;&
Expand Down
3 changes: 3 additions & 0 deletions hack/bats
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ fi
# Used in 120-load test to identify rootless destination for podman image scp
export PODMAN_ROOTLESS_USER=$(id -un)

# Make sure to always check for leaks when running locally
export PODMAN_BATS_LEAK_CHECK=1

# Root
if [[ "$TEST_ROOT" ]]; then
echo "# bats ${bats_filter[*]} $TESTS"
Expand Down
16 changes: 9 additions & 7 deletions test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ echo $rand | 0 | $rand
# a way to do so.
eval set "$cmd"

# FIXME: The </dev/null is a hack, necessary because as of 2019-09
# podman-remote has a bug in which it silently slurps up stdin,
# including the output of parse_table (i.e. tests to be run).
run_podman $expected_rc run $IMAGE "$@"
run_podman $expected_rc run --rm $IMAGE "$@"
is "$output" "$expected_output" "podman run $cmd - output"

tests_run=$(expr $tests_run + 1)
Expand Down Expand Up @@ -1313,9 +1310,9 @@ kube play | argument |
logout | $IMAGE |
manifest add | $IMAGE argument |
manifest inspect | $IMAGE |
manifest push | $IMAGE argument |
pull | $IMAGE argument |
push | $IMAGE argument |
manifest push | $IMAGE |
pull | $IMAGE |
push | $IMAGE |
run | $IMAGE false |
search | $IMAGE |
"
Expand Down Expand Up @@ -1346,6 +1343,9 @@ search | $IMAGE |
"$command REGISTRY_AUTH_FILE=nonexistent-path"
fi
done < <(parse_table "$tests")

# test cases above create two containers
run_podman rm -fa
}

@test "podman --syslog and environment passed to conmon" {
Expand Down Expand Up @@ -1501,6 +1501,8 @@ search | $IMAGE |
# This should be safe because stop is guaranteed to call cleanup?
run_podman inspect --format "{{ .State.Status }}" testctr
is "$output" "exited" "container has successfully transitioned to exited state after stop"

run_podman rm -f -t0 testctr
}

# vim: filetype=sh
3 changes: 3 additions & 0 deletions test/system/035-logs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ function _log_test_restarted() {
expected=$(mktemp -p ${PODMAN_TMPDIR} expectedXXXXXXXX)
seq 1 20 > $expected
diff -u ${expected} ${logfile}

run_podman rm -f -t0 logtest
}

@test "podman logs restarted - k8s-file" {
Expand All @@ -165,6 +167,7 @@ function _log_test_restarted() {
run_podman --events-backend=file logs test
run_podman 125 --events-backend=file logs --follow test
is "$output" "Error: using --follow with the journald --log-driver but without the journald --events-backend (file) is not supported" "journald logger requires journald eventer"
run_podman rm test
}

function _log_test_since() {
Expand Down
5 changes: 5 additions & 0 deletions test/system/045-start.bats
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ load helpers
# Nothing on match
run_podman start --filter restart-policy=none --all
is "$output" ""

run_podman rm -f $c1 $c2 $c3
}

@test "podman start --filter invalid-restart-policy - return error" {
Expand All @@ -76,6 +78,7 @@ load helpers
run_podman 125 start --filter restart-policy=fakepolicy $cid
is "$output" "Error: fakepolicy invalid restart policy" \
"CID of restart-policy=<not-exists> container"
run_podman rm -f $cid
}

@test "podman start --all --filter" {
Expand All @@ -87,6 +90,8 @@ load helpers
run_podman wait $cid_exited_0 $cid_exited_1
run_podman start --all --filter exited=0
is "$output" "$cid_exited_0"

run_podman rm -f $cid_exited_0 $cid_exited_1
}

@test "podman start print IDs or raw input" {
Expand Down
8 changes: 8 additions & 0 deletions test/system/050-stop.bats
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ load helpers
@test "podman stop --all" {
# Start three containers, create (without running) a fourth
run_podman run -d --name c1 $IMAGE sleep 20
cid1="$output"
run_podman run -d --name c2 $IMAGE sleep 40
cid2="$output"
run_podman run -d --name c3 $IMAGE sleep 60
cid3="$output"
run_podman create --name c4 $IMAGE sleep 80
cid4="$output"

# podman ps (without -a) should show the three running containers
run_podman ps --sort names --format '{{.Names}}--{{.Status}}'
Expand Down Expand Up @@ -71,6 +75,8 @@ load helpers
is "${lines[1]}" "c2--Exited.*" "ps -a, second stopped container"
is "${lines[2]}" "c3--Exited.*" "ps -a, third stopped container"
is "${lines[3]}" "c4--Created.*" "ps -a, created container (unaffected)"

run_podman rm $cid1 $cid2 $cid3 $cid4
}

@test "podman stop print IDs or raw input" {
Expand Down Expand Up @@ -194,6 +200,8 @@ load helpers
# Exit code should be 137 as it was killed
run_podman inspect --format '{{.State.ExitCode}}' stopme
is "$output" "137" "Exit code of killed container"

run_podman rm stopme
}

@test "podman stop -t 1 Generate warning" {
Expand Down
5 changes: 3 additions & 2 deletions test/system/060-mount.bats
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,12 @@ EOF
is "$output" ".*$v1a" "podman images --inspect should include $v1a"
is "$output" ".*$v1b" "podman images --inspect should include $v1b"

run_podman create --rm --mount type=glob,src=${PODMAN_TMPDIR}/v1\*,ro $IMAGE ls $vol1a $vol1b
run_podman create --mount type=glob,src=${PODMAN_TMPDIR}/v1\*,ro $IMAGE ls $vol1a $vol1b
cid=$output
run_podman container inspect $output
run_podman container inspect $cid
is "$output" ".*$vol1a" "podman images --inspect should include $vol1a"
is "$output" ".*$vol1b" "podman images --inspect should include $vol1b"
run_podman rm $cid

run_podman 125 run --rm --mount type=bind,source=${PODMAN_TMPDIR}/v2\*,ro=false $IMAGE touch $vol2
is "$output" "Error: must set volume destination" "Bind mounts require destination"
Expand Down
1 change: 1 addition & 0 deletions test/system/070-build.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1134,6 +1134,7 @@ EOF
run_podman run --rm --volumes-from test_ctr $IMAGE echo $rand_content
is "$output" "$rand_content" "No error should be thrown about volume in use"

run_podman rm -f -v -t0 test_ctr
run_podman rmi -f build_test
}

Expand Down
4 changes: 4 additions & 0 deletions test/system/075-exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ load helpers

run_podman inspect --format "{{len .ExecIDs}}" $cid
assert "$output" = "0" ".ExecIDs must be empty"

run_podman rm -f -t0 $cid
}

# 'exec --preserve-fd' passes a list of additional file descriptors into the container
Expand All @@ -239,6 +241,8 @@ load helpers
assert "${lines[0]}" !~ [123][0-9] "/proc/self/fd must not contain 10-39"
assert "${lines[1]}" = "fd9" "cat from fd 9"
assert "${lines[2]}" = "$content" "cat from fd 40"

run_podman rm -f -t0 $cid
}

# vim: filetype=sh
4 changes: 3 additions & 1 deletion test/system/090-events.bats
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function _events_disjunctive_filters() {
run_podman 125 --events-backend=file logs --follow test
is "$output" "Error: using --follow with the journald --log-driver but without the journald --events-backend (file) is not supported" \
"Should fail with reasonable error message when events-backend and events-logger do not match"

run_podman rm test
}

@test "events with disjunctive filters - default" {
Expand Down Expand Up @@ -358,6 +358,8 @@ EOF
--stream=false
assert "$output" != ".*ConmonPidFile.*"
assert "$output" != ".*EffectiveCaps.*"

run_podman rm $cname
}

@test "events - container inspect data - journald" {
Expand Down
1 change: 1 addition & 0 deletions test/system/120-load.bats
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function teardown() {
# annotations and image digests may be different. See
# https://github.com/containers/podman/discussions/17911
run_podman rmi -a -f
_prefetch $IMAGE

basic_teardown
}
Expand Down
2 changes: 2 additions & 0 deletions test/system/130-kill.bats
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ load helpers
run_podman 125 start $random_name
# FIXME(#14873): while older Podmans return 0 on wait, Docker does not.
run_podman wait $random_name
run_podman rm $random_name
}

@test "podman kill - no restart" {
Expand All @@ -149,6 +150,7 @@ load helpers
is "$output" "42" "container exits with 42 on receiving SIGTERM"
run_podman container inspect --format "{{.State.StoppedByUser}}" $ctr
is "$output" "true" "container is marked to be stopped by a user"
run_podman rm $ctr
}

# vim: filetype=sh
8 changes: 6 additions & 2 deletions test/system/150-login.bats
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,13 @@ function _test_skopeo_credential_sharing() {
--tls-verify=false $mid \
$image1
run_podman rmi $image1

run_podman images $IMAGE --format {{.ID}}
local podman_image_id=$output

run_podman pull -q --retry 4 --retry-delay "0s" --authfile=$authfile \
--tls-verify=false $image1
assert "${output:0:12}" = "$PODMAN_TEST_IMAGE_ID" "First pull (before stopping registry)"
assert "${output:0:12}" = "$podman_image_id" "First pull (before stopping registry)"
run_podman rmi $image1

# This actually STOPs the registry, so the port is unbound...
Expand All @@ -361,7 +365,7 @@ function _test_skopeo_credential_sharing() {
run_podman 0+w pull -q --retry 4 --retry-delay "5s" --authfile=$authfile \
--tls-verify=false $image1
assert "$output" =~ "Failed, retrying in 5s.*Error: initializing.* connection refused"
assert "${lines[-1]:0:12}" = "$PODMAN_TEST_IMAGE_ID" "push should succeed via retry"
assert "${lines[-1]:0:12}" = "$podman_image_id" "push should succeed via retry"
unpause_registry

run_podman rmi $image1
Expand Down
1 change: 1 addition & 0 deletions test/system/200-pod.bats
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ spec:
is "$output" "stop" "custom exit policy"
_ensure_pod_state $name-pod Exited
run_podman pod rm $name-pod
run_podman network rm podman-default-kube-network
}

@test "pod resource limits" {
Expand Down
4 changes: 4 additions & 0 deletions test/system/250-systemd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ LISTEN_FDNAMES=listen_fdnames" | sort)
run_podman create --name $cname $IMAGE top
run_podman 125 generate systemd --new=false --template -n $cname
is "$output" ".*--template cannot be set" "Error message should be '--template requires --new'"
run_podman rm $cname
}

@test "podman --cgroup=cgroupfs doesn't show systemd warning" {
Expand All @@ -287,6 +288,7 @@ LISTEN_FDNAMES=listen_fdnames" | sort)
container_uuid=$output
run_podman inspect test --format '{{ .ID }}'
is "${container_uuid}" "${output:0:32}" "UUID should be first 32 chars of Container id"
run_podman rm test
}

@test "podman --systemd fails on cgroup v1 with a private cgroupns" {
Expand Down Expand Up @@ -480,6 +482,7 @@ $name stderr" "logs work with passthrough"
run_podman 1 container exists $service_container
run_podman 1 pod exists test_pod
run_podman rmi $(pause_image)
run_podman network rm podman-default-kube-network
rm -f $UNIT_DIR/$unit_name
}

Expand All @@ -492,5 +495,6 @@ $name stderr" "logs work with passthrough"
is "$output" ".*[DEPRECATED] command:"
run_podman generate --help
is "$output" ".*\[DEPRECATED\] Generate systemd units"
run_podman rm test
}
# vim: filetype=sh
9 changes: 9 additions & 0 deletions test/system/252-quadlet.bats
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ EOF
is "$output" "with space"

service_cleanup $QUADLET_SERVICE_NAME inactive
run_podman volume rm $volume_name
}

# A quadlet container depends on a quadlet volume
Expand Down Expand Up @@ -450,6 +451,7 @@ EOF
is "$output" "with space"

service_cleanup $QUADLET_SERVICE_NAME inactive
run_podman network rm $network_name
}

# A quadlet container depends on a quadlet network
Expand Down Expand Up @@ -591,6 +593,7 @@ EOF

service_cleanup $QUADLET_SERVICE_NAME inactive
run_podman rmi $(pause_image)
run_podman network rm podman-default-kube-network
}

@test "quadlet kube - named network dependency" {
Expand Down Expand Up @@ -960,6 +963,7 @@ EOF
done < <(parse_table "$exit_tests")

run_podman rmi $(pause_image)
run_podman network rm podman-default-kube-network
}

@test "quadlet kube - Working Directory" {
Expand Down Expand Up @@ -1020,6 +1024,7 @@ EOF

service_cleanup $QUADLET_SERVICE_NAME inactive
run_podman rmi $(pause_image)
run_podman network rm podman-default-kube-network
}

@test "quadlet - image files" {
Expand Down Expand Up @@ -1251,6 +1256,7 @@ EOF
service_cleanup $pod_service inactive
run_podman volume rm $quadlet_kube_volume_name
run_podman rmi --ignore $(pause_image)
run_podman network rm podman-default-kube-network
}

@test "quadlet - kube down force" {
Expand Down Expand Up @@ -1330,6 +1336,7 @@ EOF
# Volume should not exist
run_podman 1 volume exists ${quadlet_kube_volume_name}
run_podman rmi --ignore $(pause_image)
run_podman network rm podman-default-kube-network
}

@test "quadlet - image tag" {
Expand Down Expand Up @@ -1417,6 +1424,7 @@ EOF
service_cleanup $container_service failed
run_podman image rm --ignore $image_for_test
run_podman rmi --ignore $(pause_image)
run_podman volume rm $volume_name
}

@test "quadlet - pod simple" {
Expand Down Expand Up @@ -1546,5 +1554,6 @@ EOF

service_cleanup $QUADLET_SERVICE_NAME inactive
run_podman rmi $untagged_image:latest $built_image $(pause_image)
run_podman network rm podman-default-kube-network
}
# vim: filetype=sh
1 change: 1 addition & 0 deletions test/system/255-auto-update.bats
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ EOF
# Clean up
systemctl stop $service_name
run_podman rmi -f $(pause_image) $local_image $newID $oldID
run_podman network rm podman-default-kube-network
rm -f $UNIT_DIR/$unit_name
}

Expand Down
Loading

0 comments on commit b869efa

Please sign in to comment.