From d92f2d39ee6e9c248e5ddfd279da36eee3904f96 Mon Sep 17 00:00:00 2001 From: Ed Santiago Date: Wed, 18 Sep 2024 06:31:49 -0600 Subject: [PATCH] CI: make 700-play parallel-safe (where possible. Not all tests are parallelizable). And, refactor two complicated tests into one. This one is hard to review, sorry. Signed-off-by: Ed Santiago --- test/system/700-play.bats | 203 +++++++++++++++++++------------------- 1 file changed, 101 insertions(+), 102 deletions(-) diff --git a/test/system/700-play.bats b/test/system/700-play.bats index 7fe6d18db1..ce5011bd82 100644 --- a/test/system/700-play.bats +++ b/test/system/700-play.bats @@ -7,21 +7,6 @@ load helpers load helpers.network load helpers.registry -# This is a long ugly way to clean up pods and remove the pause image -function teardown() { - run_podman pod rm -t 0 -f -a - run_podman rm -t 0 -f -a - run_podman image list --format '{{.ID}} {{.Repository}}' - while read id name; do - if [[ "$name" =~ /podman-pause ]]; then - run_podman rmi $id - fi - done <<<"$output" - run_podman network rm -f podman-default-kube-network - - basic_teardown -} - # helper function: writes a yaml file with customizable values function _write_test_yaml() { # All of these are available to our caller @@ -120,6 +105,7 @@ EOF RELABEL="system_u:object_r:container_file_t:s0" +# bats test_tags=ci:parallel @test "podman kube with stdin" { TESTDIR=$PODMAN_TMPDIR/testdir mkdir -p $TESTDIR @@ -140,6 +126,7 @@ RELABEL="system_u:object_r:container_file_t:s0" run_podman pod rm -t 0 -f $PODNAME } +# bats test_tags=ci:parallel @test "podman play" { # Testing that the "podman play" cmd still works now that # "podman kube" is an option. @@ -161,6 +148,7 @@ RELABEL="system_u:object_r:container_file_t:s0" run_podman pod rm -t 0 -f $PODNAME } +# bats test_tags=ci:parallel @test "podman play --service-container" { skip_if_remote "service containers only work locally" @@ -226,11 +214,14 @@ RELABEL="system_u:object_r:container_file_t:s0" run_podman pod kill $PODNAME _ensure_container_running $service_container false + run_podman network ls + # Remove the pod and make sure the service is removed along with it run_podman pod rm $PODNAME run_podman 1 container exists $service_container } +# bats test_tags=ci:parallel @test "podman kube --network" { _write_test_yaml command=top @@ -262,6 +253,7 @@ RELABEL="system_u:object_r:container_file_t:s0" run_podman 1 container exists $PODCTRNAME } +# bats test_tags=ci:parallel @test "podman kube play read-only" { YAML=$PODMAN_TMPDIR/test.yml @@ -300,6 +292,7 @@ RELABEL="system_u:object_r:container_file_t:s0" run_podman 1 container exists ${podname}-${c3name} } +# bats test_tags=ci:parallel @test "podman kube play read-only from containers.conf" { containersconf=$PODMAN_TMPDIR/containers.conf cat >$containersconf <>$TESTYAML <$fname apiVersion: v1 kind: Pod metadata: @@ -871,93 +897,62 @@ spec: - touch /tmp/healthy && sleep 100 livenessProbe: exec: + # /tmp/healthy will exist in healthy container + # /tmp/unhealthy will never exist, and will thus + # cause healthcheck failure command: - cat - - /tmp/healthy + - /tmp/$want initialDelaySeconds: 3 failureThreshold: 1 periodSeconds: 1 -" > $fname +EOF - run_podman kube play $fname - ctrName="$podname-$ctrname" + run_podman kube play $fname + ctrName="$podname-$ctrname" - # Keep checking status. For the first 2 seconds it must be 'starting' - t0=$SECONDS - while [[ $SECONDS -le $((t0 + 2)) ]]; do - run_podman inspect $ctrName --format "1-{{.State.Health.Status}}" - assert "$output" == "1-starting" "Health.Status at $((SECONDS - t0))" - sleep 0.5 - done + # Collect status every half-second until it goes into the desired state. + local i=1 + local full_log="" + while [[ $i -lt 15 ]]; do + run_podman inspect $ctrName --format "$i-{{.State.Health.Status}}" + full_log+=" $output" + if [[ "$output" =~ "-$want" ]]; then + break + fi + sleep 0.5 + i=$((i+1)) + done - # After 3 seconds it may take another second to go healthy. Wait. - t0=$SECONDS - while [[ $SECONDS -le $((t0 + 3)) ]]; do - run_podman inspect $ctrName --format "2-{{.State.Health.Status}}" - if [[ "$output" = "2-healthy" ]]; then - break; + assert "$full_log" =~ "-$want\$" \ + "Container got to '$want'" + assert "$full_log" =~ "-starting.*-$want" \ + "Container went from starting to $want" + + if [[ $want == "healthy" ]]; then + dontwant="unhealthy" + else + dontwant="healthy" fi - sleep 0.5 - done - assert $output == "2-healthy" "After 3 seconds" + assert "$full_log" !~ "-$dontwant" \ + "Container never goes $dontwant" - run_podman kube down $fname -} - -@test "podman kube play healthcheck should wait initialDelaySeconds before updating status (unhealthy)" { - podname="liveness-exec-$(safename)" - ctrname="liveness-ctr-$(safename)" - - fname="$PODMAN_TMPDIR/play_kube_unhealthy_$(random_string 6).yaml" - echo " -apiVersion: v1 -kind: Pod -metadata: - labels: - name: $podname -spec: - containers: - - name: $ctrname - image: $IMAGE - args: - - /bin/sh - - -c - - touch /tmp/healthy && sleep 100 - livenessProbe: - exec: - command: - - cat - - /tmp/randomfile - initialDelaySeconds: 3 - failureThreshold: 1 - periodSeconds: 1 -" > $fname - - run_podman kube play $fname - ctrName="$podname-$ctrname" - - # Keep checking status. For the first 2 seconds it must be 'starting' - t0=$SECONDS - while [[ $SECONDS -le $((t0 + 2)) ]]; do - run_podman inspect $ctrName --format "1-{{.State.Health.Status}}" - assert "$output" == "1-starting" "Health.Status at $((SECONDS - t0))" - sleep 0.5 - done - - # After 3 seconds it may take another second to go unhealthy. Wait. - t0=$SECONDS - while [[ $SECONDS -le $((t0 + 3)) ]]; do - run_podman inspect $ctrName --format "2-{{.State.Health.Status}}" - if [[ "$output" = "2-unhealthy" ]]; then - break; - fi - sleep 0.5 - done - assert $output == "2-unhealthy" "After 3 seconds" - - run_podman kube down $fname + # GAH! Save ten seconds, but in a horrible way. + # - 'kube down' does not have a -t0 option. + # - Using 'top' in the container, instead of 'sleep 100', results + # in very weird failures. Seriously weird. + # - 'stop -t0', every once in a while on parallel runs on my + # laptop (never yet in CI), barfs with 'container is running or + # paused, refusing to clean up, container state improper' + # Here's hoping that this will silence the flakes. + run_podman '?' stop -t0 $ctrName + + run_podman kube down $fname + done } +# CANNOT BE PARALLELIZED (YET): buildah#5674, parallel builds fail +# ...workaround is --layers=false, but there's no way to do that in kube @test "podman play --build private registry" { skip_if_remote "--build is not supported in context remote" @@ -1001,6 +996,7 @@ _EOF run_podman rmi -f $userimage $from_image } +# bats test_tags=ci:parallel @test "podman play with image volume (automount annotation and OCI VolumeSource)" { imgname1="automount-img1-$(safename)" imgname2="automount-img2-$(safename)" @@ -1026,8 +1022,9 @@ VOLUME /test2 VOLUME /test_same EOF - run_podman build -t $imgname1 -f $PODMAN_TMPDIR/Containerfile1 - run_podman build -t $imgname2 -f $PODMAN_TMPDIR/Containerfile2 + # --layers=false needed to work around buildah#5674 parallel flake + run_podman build -t $imgname1 --layers=false -f $PODMAN_TMPDIR/Containerfile1 + run_podman build -t $imgname2 --layers=false -f $PODMAN_TMPDIR/Containerfile2 _write_test_yaml command=top name=$podname ctrname=$ctrname run_podman kube play --annotation "io.podman.annotations.kube.image.volumes.mount/$ctrname=$imgname1" $TESTYAML @@ -1141,6 +1138,7 @@ EOF run_podman rmi $imgname1 $imgname2 } +# bats test_tags=ci:parallel @test "podman play with image volume pull policies" { podname="p-$(safename)" ctrname="c-$(safename)" @@ -1234,6 +1232,7 @@ EOF run_podman rmi $volimg_local $volimg_both } +# CANNOT BE PARALLELIZED: userns=auto, rootless, => not enough unused IDs in user namespace @test "podman kube restore user namespace" { if ! is_rootless; then grep -E -q "^containers:" /etc/subuid || skip "no IDs allocated for user 'containers'"