Skip to content

Commit b869efa

Browse files
Merge pull request #22909 from Luap99/fast-system-test-4
test/system: speed up basic_{setup,teardown}()
2 parents afe55cd + 0eaec1a commit b869efa

29 files changed

+260
-119
lines changed

contrib/cirrus/lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ EPOCH_TEST_COMMIT="$CIRRUS_BASE_SHA"
9494
# are consumed by the passthrough_envars() automation library function.
9595
#
9696
# List of envariables which must be EXACT matches
97-
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'
97+
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'
9898

9999
# List of envariable patterns which must match AT THE BEGINNING of the name.
100100
# Consumed by the passthrough_envars() automation library function.

contrib/cirrus/setup_environment.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,13 @@ case "$TEST_FLAVOR" in
365365
int)
366366
showrun make .install.ginkgo
367367
;&
368-
sys) ;&
368+
sys)
369+
# when run nighlty check for system test leaks
370+
# shellcheck disable=SC2154
371+
if [[ "$CIRRUS_CRON" != '' ]]; then
372+
export PODMAN_BATS_LEAK_CHECK=1
373+
fi
374+
;&
369375
upgrade_test) ;&
370376
bud) ;&
371377
bindings) ;&

hack/bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ fi
125125
# Used in 120-load test to identify rootless destination for podman image scp
126126
export PODMAN_ROOTLESS_USER=$(id -un)
127127

128+
# Make sure to always check for leaks when running locally
129+
export PODMAN_BATS_LEAK_CHECK=1
130+
128131
# Root
129132
if [[ "$TEST_ROOT" ]]; then
130133
echo "# bats ${bats_filter[*]} $TESTS"

test/system/030-run.bats

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ echo $rand | 0 | $rand
3737
# a way to do so.
3838
eval set "$cmd"
3939

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

4643
tests_run=$(expr $tests_run + 1)
@@ -1313,9 +1310,9 @@ kube play | argument |
13131310
logout | $IMAGE |
13141311
manifest add | $IMAGE argument |
13151312
manifest inspect | $IMAGE |
1316-
manifest push | $IMAGE argument |
1317-
pull | $IMAGE argument |
1318-
push | $IMAGE argument |
1313+
manifest push | $IMAGE |
1314+
pull | $IMAGE |
1315+
push | $IMAGE |
13191316
run | $IMAGE false |
13201317
search | $IMAGE |
13211318
"
@@ -1346,6 +1343,9 @@ search | $IMAGE |
13461343
"$command REGISTRY_AUTH_FILE=nonexistent-path"
13471344
fi
13481345
done < <(parse_table "$tests")
1346+
1347+
# test cases above create two containers
1348+
run_podman rm -fa
13491349
}
13501350

13511351
@test "podman --syslog and environment passed to conmon" {
@@ -1501,6 +1501,8 @@ search | $IMAGE |
15011501
# This should be safe because stop is guaranteed to call cleanup?
15021502
run_podman inspect --format "{{ .State.Status }}" testctr
15031503
is "$output" "exited" "container has successfully transitioned to exited state after stop"
1504+
1505+
run_podman rm -f -t0 testctr
15041506
}
15051507

15061508
# vim: filetype=sh

test/system/035-logs.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ function _log_test_restarted() {
143143
expected=$(mktemp -p ${PODMAN_TMPDIR} expectedXXXXXXXX)
144144
seq 1 20 > $expected
145145
diff -u ${expected} ${logfile}
146+
147+
run_podman rm -f -t0 logtest
146148
}
147149

148150
@test "podman logs restarted - k8s-file" {
@@ -165,6 +167,7 @@ function _log_test_restarted() {
165167
run_podman --events-backend=file logs test
166168
run_podman 125 --events-backend=file logs --follow test
167169
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"
170+
run_podman rm test
168171
}
169172

170173
function _log_test_since() {

test/system/045-start.bats

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ load helpers
6868
# Nothing on match
6969
run_podman start --filter restart-policy=none --all
7070
is "$output" ""
71+
72+
run_podman rm -f $c1 $c2 $c3
7173
}
7274

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

8184
@test "podman start --all --filter" {
@@ -87,6 +90,8 @@ load helpers
8790
run_podman wait $cid_exited_0 $cid_exited_1
8891
run_podman start --all --filter exited=0
8992
is "$output" "$cid_exited_0"
93+
94+
run_podman rm -f $cid_exited_0 $cid_exited_1
9095
}
9196

9297
@test "podman start print IDs or raw input" {

test/system/050-stop.bats

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ load helpers
3939
@test "podman stop --all" {
4040
# Start three containers, create (without running) a fourth
4141
run_podman run -d --name c1 $IMAGE sleep 20
42+
cid1="$output"
4243
run_podman run -d --name c2 $IMAGE sleep 40
44+
cid2="$output"
4345
run_podman run -d --name c3 $IMAGE sleep 60
46+
cid3="$output"
4447
run_podman create --name c4 $IMAGE sleep 80
48+
cid4="$output"
4549

4650
# podman ps (without -a) should show the three running containers
4751
run_podman ps --sort names --format '{{.Names}}--{{.Status}}'
@@ -71,6 +75,8 @@ load helpers
7175
is "${lines[1]}" "c2--Exited.*" "ps -a, second stopped container"
7276
is "${lines[2]}" "c3--Exited.*" "ps -a, third stopped container"
7377
is "${lines[3]}" "c4--Created.*" "ps -a, created container (unaffected)"
78+
79+
run_podman rm $cid1 $cid2 $cid3 $cid4
7480
}
7581

7682
@test "podman stop print IDs or raw input" {
@@ -194,6 +200,8 @@ load helpers
194200
# Exit code should be 137 as it was killed
195201
run_podman inspect --format '{{.State.ExitCode}}' stopme
196202
is "$output" "137" "Exit code of killed container"
203+
204+
run_podman rm stopme
197205
}
198206

199207
@test "podman stop -t 1 Generate warning" {

test/system/060-mount.bats

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,12 @@ EOF
283283
is "$output" ".*$v1a" "podman images --inspect should include $v1a"
284284
is "$output" ".*$v1b" "podman images --inspect should include $v1b"
285285

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

292293
run_podman 125 run --rm --mount type=bind,source=${PODMAN_TMPDIR}/v2\*,ro=false $IMAGE touch $vol2
293294
is "$output" "Error: must set volume destination" "Bind mounts require destination"

test/system/070-build.bats

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ EOF
11341134
run_podman run --rm --volumes-from test_ctr $IMAGE echo $rand_content
11351135
is "$output" "$rand_content" "No error should be thrown about volume in use"
11361136

1137+
run_podman rm -f -v -t0 test_ctr
11371138
run_podman rmi -f build_test
11381139
}
11391140

test/system/075-exec.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ load helpers
217217

218218
run_podman inspect --format "{{len .ExecIDs}}" $cid
219219
assert "$output" = "0" ".ExecIDs must be empty"
220+
221+
run_podman rm -f -t0 $cid
220222
}
221223

222224
# 'exec --preserve-fd' passes a list of additional file descriptors into the container
@@ -239,6 +241,8 @@ load helpers
239241
assert "${lines[0]}" !~ [123][0-9] "/proc/self/fd must not contain 10-39"
240242
assert "${lines[1]}" = "fd9" "cat from fd 9"
241243
assert "${lines[2]}" = "$content" "cat from fd 40"
244+
245+
run_podman rm -f -t0 $cid
242246
}
243247

244248
# vim: filetype=sh

test/system/090-events.bats

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function _events_disjunctive_filters() {
134134
run_podman 125 --events-backend=file logs --follow test
135135
is "$output" "Error: using --follow with the journald --log-driver but without the journald --events-backend (file) is not supported" \
136136
"Should fail with reasonable error message when events-backend and events-logger do not match"
137-
137+
run_podman rm test
138138
}
139139

140140
@test "events with disjunctive filters - default" {
@@ -358,6 +358,8 @@ EOF
358358
--stream=false
359359
assert "$output" != ".*ConmonPidFile.*"
360360
assert "$output" != ".*EffectiveCaps.*"
361+
362+
run_podman rm $cname
361363
}
362364

363365
@test "events - container inspect data - journald" {

test/system/120-load.bats

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function teardown() {
1515
# annotations and image digests may be different. See
1616
# https://github.com/containers/podman/discussions/17911
1717
run_podman rmi -a -f
18+
_prefetch $IMAGE
1819

1920
basic_teardown
2021
}

test/system/130-kill.bats

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ load helpers
135135
run_podman 125 start $random_name
136136
# FIXME(#14873): while older Podmans return 0 on wait, Docker does not.
137137
run_podman wait $random_name
138+
run_podman rm $random_name
138139
}
139140

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

154156
# vim: filetype=sh

test/system/150-login.bats

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,13 @@ function _test_skopeo_credential_sharing() {
349349
--tls-verify=false $mid \
350350
$image1
351351
run_podman rmi $image1
352+
353+
run_podman images $IMAGE --format {{.ID}}
354+
local podman_image_id=$output
355+
352356
run_podman pull -q --retry 4 --retry-delay "0s" --authfile=$authfile \
353357
--tls-verify=false $image1
354-
assert "${output:0:12}" = "$PODMAN_TEST_IMAGE_ID" "First pull (before stopping registry)"
358+
assert "${output:0:12}" = "$podman_image_id" "First pull (before stopping registry)"
355359
run_podman rmi $image1
356360

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

367371
run_podman rmi $image1

test/system/200-pod.bats

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ spec:
508508
is "$output" "stop" "custom exit policy"
509509
_ensure_pod_state $name-pod Exited
510510
run_podman pod rm $name-pod
511+
run_podman network rm podman-default-kube-network
511512
}
512513

513514
@test "pod resource limits" {

test/system/250-systemd.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ LISTEN_FDNAMES=listen_fdnames" | sort)
275275
run_podman create --name $cname $IMAGE top
276276
run_podman 125 generate systemd --new=false --template -n $cname
277277
is "$output" ".*--template cannot be set" "Error message should be '--template requires --new'"
278+
run_podman rm $cname
278279
}
279280

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

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

@@ -492,5 +495,6 @@ $name stderr" "logs work with passthrough"
492495
is "$output" ".*[DEPRECATED] command:"
493496
run_podman generate --help
494497
is "$output" ".*\[DEPRECATED\] Generate systemd units"
498+
run_podman rm test
495499
}
496500
# vim: filetype=sh

test/system/252-quadlet.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ EOF
324324
is "$output" "with space"
325325

326326
service_cleanup $QUADLET_SERVICE_NAME inactive
327+
run_podman volume rm $volume_name
327328
}
328329

329330
# A quadlet container depends on a quadlet volume
@@ -450,6 +451,7 @@ EOF
450451
is "$output" "with space"
451452

452453
service_cleanup $QUADLET_SERVICE_NAME inactive
454+
run_podman network rm $network_name
453455
}
454456

455457
# A quadlet container depends on a quadlet network
@@ -591,6 +593,7 @@ EOF
591593

592594
service_cleanup $QUADLET_SERVICE_NAME inactive
593595
run_podman rmi $(pause_image)
596+
run_podman network rm podman-default-kube-network
594597
}
595598

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

962965
run_podman rmi $(pause_image)
966+
run_podman network rm podman-default-kube-network
963967
}
964968

965969
@test "quadlet kube - Working Directory" {
@@ -1020,6 +1024,7 @@ EOF
10201024

10211025
service_cleanup $QUADLET_SERVICE_NAME inactive
10221026
run_podman rmi $(pause_image)
1027+
run_podman network rm podman-default-kube-network
10231028
}
10241029

10251030
@test "quadlet - image files" {
@@ -1251,6 +1256,7 @@ EOF
12511256
service_cleanup $pod_service inactive
12521257
run_podman volume rm $quadlet_kube_volume_name
12531258
run_podman rmi --ignore $(pause_image)
1259+
run_podman network rm podman-default-kube-network
12541260
}
12551261

12561262
@test "quadlet - kube down force" {
@@ -1330,6 +1336,7 @@ EOF
13301336
# Volume should not exist
13311337
run_podman 1 volume exists ${quadlet_kube_volume_name}
13321338
run_podman rmi --ignore $(pause_image)
1339+
run_podman network rm podman-default-kube-network
13331340
}
13341341

13351342
@test "quadlet - image tag" {
@@ -1417,6 +1424,7 @@ EOF
14171424
service_cleanup $container_service failed
14181425
run_podman image rm --ignore $image_for_test
14191426
run_podman rmi --ignore $(pause_image)
1427+
run_podman volume rm $volume_name
14201428
}
14211429

14221430
@test "quadlet - pod simple" {
@@ -1546,5 +1554,6 @@ EOF
15461554

15471555
service_cleanup $QUADLET_SERVICE_NAME inactive
15481556
run_podman rmi $untagged_image:latest $built_image $(pause_image)
1557+
run_podman network rm podman-default-kube-network
15491558
}
15501559
# vim: filetype=sh

test/system/255-auto-update.bats

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ EOF
564564
# Clean up
565565
systemctl stop $service_name
566566
run_podman rmi -f $(pause_image) $local_image $newID $oldID
567+
run_podman network rm podman-default-kube-network
567568
rm -f $UNIT_DIR/$unit_name
568569
}
569570

0 commit comments

Comments
 (0)