Merge pull request #22886 from Luap99/fast-system-test-3

test/system: make some tests faster part 3
This commit is contained in:
openshift-merge-bot[bot] 2024-06-05 13:19:00 +00:00 committed by GitHub
commit 42ffa4db43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 130 additions and 119 deletions

View File

@ -665,7 +665,7 @@ localmachine:
localsystem:
# Wipe existing config, database, and cache: start with clean slate.
$(RM) -rf ${HOME}/.local/share/containers ${HOME}/.config/containers
if timeout -v 1 true; then PODMAN=$(CURDIR)/bin/podman QUADLET=$(CURDIR)/bin/quadlet bats test/system/; else echo "Skipping $@: 'timeout -v' unavailable'"; fi
if timeout -v 1 true; then PODMAN=$(CURDIR)/bin/podman QUADLET=$(CURDIR)/bin/quadlet bats -T test/system/; else echo "Skipping $@: 'timeout -v' unavailable'"; fi
.PHONY: remotesystem
remotesystem:
@ -690,7 +690,7 @@ remotesystem:
echo "Error: ./bin/podman system service did not come up on $$SOCK_FILE" >&2;\
exit 1;\
fi;\
env PODMAN="$(CURDIR)/bin/podman-remote --url $$PODMAN_SOCKET" bats test/system/ ;\
env PODMAN="$(CURDIR)/bin/podman-remote --url $$PODMAN_SOCKET" bats -T test/system/ ;\
rc=$$?;\
kill %1;\
rm -f $$SOCK_FILE;\

View File

@ -195,10 +195,10 @@ See 'podman version --help'" "podman version --remote"
}
@test "podman --log-level recognizes log levels" {
run_podman 1 --log-level=telepathic info
run_podman 1 --log-level=telepathic version
is "$output" 'Log Level "telepathic" is not supported.*'
run_podman --log-level=trace info
run_podman --log-level=trace version
if ! is_remote; then
# podman-remote does not do any trace logging
assert "$output" =~ " level=trace " "log-level=trace"
@ -207,33 +207,33 @@ See 'podman version --help'" "podman version --remote"
assert "$output" =~ " level=info " "log-level=trace includes info"
assert "$output" !~ " level=warn" "log-level=trace does not show warn"
run_podman --log-level=debug info
run_podman --log-level=debug version
assert "$output" !~ " level=trace " "log-level=debug does not show trace"
assert "$output" =~ " level=debug " "log-level=debug"
assert "$output" =~ " level=info " "log-level=debug includes info"
assert "$output" !~ " level=warn" "log-level=debug does not show warn"
run_podman --log-level=info info
run_podman --log-level=info version
assert "$output" !~ " level=trace " "log-level=info does not show trace"
assert "$output" !~ " level=debug " "log-level=info does not show debug"
assert "$output" =~ " level=info " "log-level=info"
run_podman --log-level=warn info
run_podman --log-level=warn version
assert "$output" !~ " level=" "log-level=warn shows no logs at all"
run_podman --log-level=warning info
run_podman --log-level=warning version
assert "$output" !~ " level=" "log-level=warning shows no logs at all"
run_podman --log-level=error info
run_podman --log-level=error version
assert "$output" !~ " level=" "log-level=error shows no logs at all"
# docker compat
run_podman --debug info
run_podman --debug version
assert "$output" =~ " level=debug " "podman --debug gives debug output"
run_podman -D info
run_podman -D version
assert "$output" =~ " level=debug " "podman -D gives debug output"
run_podman 1 --debug --log-level=panic info
run_podman 1 --debug --log-level=panic version
is "$output" "Setting --log-level and --debug is not allowed"
}

View File

@ -308,12 +308,10 @@ echo $rand | 0 | $rand
for user in "--user=0" "--user=100"; do
for keepid in "" ${keep}; do
opts="$priv $user $keepid"
for dir in /etc /usr;do
run_podman run --rm $opts $IMAGE stat -c '%u:%g:%n' $dir
remove_same_dev_warning # grumble
is "$output" "0:0:$dir" "run $opts ($dir)"
done
run_podman run --rm $opts $IMAGE stat -c '%u:%g:%n' $dir /etc /usr
remove_same_dev_warning # grumble
is "${lines[0]}" "0:0:/etc" "run $opts /etc"
is "${lines[1]}" "0:0:/usr" "run $opts /usr"
done
done
done

View File

@ -142,25 +142,38 @@ load helpers
run_podman ps --external
is "${#lines[@]}" "1" "setup check: no storage containers at start of test"
# Force a buildah timeout; this leaves a buildah container behind
local t0=$SECONDS
PODMAN_TIMEOUT=5 run_podman 124 build -t thiswillneverexist - <<EOF
FROM $IMAGE
RUN touch /intermediate.image.to.be.pruned
RUN sleep 30
EOF
local t1=$SECONDS
local delta_t=$((t1 - t0))
assert $delta_t -le 10 \
"podman build did not get killed within 10 seconds"
# Ok this here is basically a way to reproduce a "leaked" podman build buildah
# container without having to kill any process and usage of sleep.
run buildah from $IMAGE
assert "$status" -eq 0 "buildah from successfully"
buildah_cid="$output"
# Commit new image so we have something to prune.
run buildah commit $buildah_cid
assert "$status" -eq 0 "buildah commit successfully"
buildah_image_id="${lines[-1]}"
# 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
is "${#lines[@]}" "1" "podman ps -a does not see buildah containers"
run_podman ps --external
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]}" \
"[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"
# 'rm -a' should be a NOP

View File

@ -360,20 +360,26 @@ load helpers
while read src dest dest_fullname description; do
run_podman cp $srcdir/$src destrunning:$dest
run_podman exec destrunning cat $dest_fullname/hostfile0 $dest_fullname/hostfile1
is "$(echo $output)" "${randomcontent[*]}" "$description (cp -> ctr:$dest - RUNNING)"
is "${lines[*]}" "${randomcontent[*]}" "$description (cp -> ctr:$dest - RUNNING)"
done < <(parse_table "$tests")
run_podman rm -t 0 -f destrunning
# CREATED container
run_podman create --name destcreated --workdir=/srv $cpimage sleep infinity
while read src dest dest_fullname description; do
run_podman create --name destcreated --workdir=/srv $cpimage sleep infinity
run_podman cp $srcdir/$src destcreated:$dest
run_podman start destcreated
run_podman exec destcreated cat $dest_fullname/hostfile0 $dest_fullname/hostfile1
is "$(echo $output)" "${randomcontent[*]}" "$description (cp -> ctr:$dest - CREATED)"
run_podman rm -t 0 -f destcreated
# tests checks are done below
done < <(parse_table "$tests")
# Now do the test checks, it is a bit ugly that we do this over two loops but this
# makes the test faster as we do not have to start/stop the container on every iteration.
run_podman start destcreated
while read src dest dest_fullname description; do
run_podman exec destcreated cat $dest_fullname/hostfile0 $dest_fullname/hostfile1
is "${lines[*]}" "${randomcontent[*]}" "$description (cp -> ctr:$dest - CREATED)"
done < <(parse_table "$tests")
run_podman rm -t 0 -f destcreated
run_podman create --name destnotdir --workdir=/srv $cpimage sleep infinity
run_podman 125 cp $srcdir destnotdir:/etc/os-release
is "$output" "Error: destination must be a directory when copying a directory" "cannot copy directory to file"

View File

@ -246,7 +246,7 @@ FROM $IMAGE
RUN echo hi
EOF
local count=30
local count=10
for i in $(seq --format '%02g' 1 $count); do
timeout --foreground -v --kill=10 60 \
$PODMAN build -t i$i $PODMAN_TMPDIR &> $PODMAN_TMPDIR/log.$i &
@ -360,11 +360,11 @@ LABEL $label_name=$label_value
WORKDIR $workdir
# Test for #7094 - chowning of invalid symlinks
RUN mkdir -p /a/b/c
RUN ln -s /no/such/nonesuch /a/b/c/badsymlink
RUN ln -s /bin/mydefaultcmd /a/b/c/goodsymlink
RUN touch /a/b/c/myfile
RUN chown -h 1:2 /a/b/c/badsymlink /a/b/c/goodsymlink && chown -h 4:5 /a/b/c/myfile
RUN mkdir -p /a/b/c && \
ln -s /no/such/nonesuch /a/b/c/badsymlink && \
ln -s /bin/mydefaultcmd /a/b/c/goodsymlink && \
touch /a/b/c/myfile && \
chown -h 1:2 /a/b/c/badsymlink /a/b/c/goodsymlink && chown -h 4:5 /a/b/c/myfile
VOLUME /a/b/c
# Test for environment passing and override
@ -374,17 +374,16 @@ ENV MYENV3 this-should-be-overridden-by-env-file
ENV MYENV4 this-should-be-overridden-by-cmdline
ENV http_proxy http-proxy-in-image
ENV ftp_proxy ftp-proxy-in-image
ADD mycmd /bin/mydefaultcmd
RUN chmod 755 /bin/mydefaultcmd
RUN chown 2:3 /bin/mydefaultcmd
RUN $CAT_SECRET
RUN echo explicit-build-arg=\$arg_explicit
RUN echo implicit-build-arg=\$arg_implicit
RUN chmod 755 /bin/mydefaultcmd && \
chown 2:3 /bin/mydefaultcmd && \
$CAT_SECRET && \
echo explicit-build-arg=\$arg_explicit && \
echo implicit-build-arg=\$arg_implicit && \
cat /etc/resolv.conf
CMD ["/bin/mydefaultcmd","$s_echo"]
RUN cat /etc/resolv.conf
EOF
# The goal is to test that a missing value will be inherited from
@ -458,7 +457,8 @@ EOF
--env-file=$PODMAN_TMPDIR/env-file1 \
--env-file=$PODMAN_TMPDIR/env-file2 \
build_test \
printenv http_proxy https_proxy ftp_proxy
sh -c "printenv http_proxy https_proxy ftp_proxy &&
pwd"
is "${lines[0]}" "http-proxy-in-env-file" "env-file overrides env"
is "${lines[1]}" "https-proxy-in-env-file" "env-file sets proxy var"
@ -469,8 +469,7 @@ EOF
fi
# test that workdir is set for command-line commands also
run_podman run --rm build_test pwd
is "$output" "$workdir" "pwd command in container"
is "${lines[3]}" "$workdir" "pwd command in container"
# Determine buildah version, so we can confirm it gets into Labels
# Multiple --format options confirm command-line override (last one wins)
@ -494,10 +493,8 @@ Cmd[0] | /bin/mydefaultcmd
Cmd[1] | $s_echo
WorkingDir | $workdir
Labels.$label_name | $label_value
Labels.\"io.buildah.version\" | $buildah_version
"
# FIXME: 2021-02-24: Fixed in buildah #3036; re-enable this once podman
# vendors in a newer buildah!
# Labels.\"io.buildah.version\" | $buildah_version
parse_table "$tests" | while read field expect; do
actual=$(jq -r ".[0].Config.$field" <<<"$output")
@ -509,19 +506,18 @@ Labels.$label_name | $label_value
# get here because any 'podman run' on a volume that had symlinks,
# be they dangling or valid, would barf with
# Error: chown <mountpath>/_data/symlink: ENOENT
run_podman run --rm build_test stat -c'%u:%g:%N' /a/b/c/badsymlink
is "$output" "1:2:'/a/b/c/badsymlink' -> '/no/such/nonesuch'" \
run_podman run --rm build_test \
stat -c'%u:%g:%N' /a/b/c/badsymlink \
/a/b/c/goodsymlink \
/bin/mydefaultcmd \
/a/b/c/myfile
is "${lines[0]}" "1:2:'/a/b/c/badsymlink' -> '/no/such/nonesuch'" \
"bad symlink to nonexistent file is chowned and preserved"
run_podman run --rm build_test stat -c'%u:%g:%N' /a/b/c/goodsymlink
is "$output" "1:2:'/a/b/c/goodsymlink' -> '/bin/mydefaultcmd'" \
is "${lines[1]}" "1:2:'/a/b/c/goodsymlink' -> '/bin/mydefaultcmd'" \
"good symlink to existing file is chowned and preserved"
run_podman run --rm build_test stat -c'%u:%g' /bin/mydefaultcmd
is "$output" "2:3" "target of symlink is not chowned"
run_podman run --rm build_test stat -c'%u:%g:%N' /a/b/c/myfile
is "$output" "4:5:/a/b/c/myfile" "file in volume is chowned"
is "${lines[2]}" "2:3:/bin/mydefaultcmd" "target of symlink is not chowned"
is "${lines[3]}" "4:5:/a/b/c/myfile" "file in volume is chowned"
# Hey, as long as we have an image with lots of layers, let's
# confirm that 'image tree' works as expected

View File

@ -150,7 +150,9 @@ function remove_secret() {
cat > $quadlet_file <<EOF
[Container]
Image=$IMAGE
Exec=sh -c "echo STARTED CONTAINER; echo "READY=1" | socat -u STDIN unix-sendto:\$NOTIFY_SOCKET; sleep inf"
# Note it is important that the trap is before the ready message,
# otherwise the signal handler may not registered in time before we do systemctl stop.
Exec=sh -c "echo STARTED CONTAINER; trap 'exit' SIGTERM; echo "READY=1" | socat -u STDIN unix-sendto:\$NOTIFY_SOCKET; while :; do sleep 0.1; done"
Notify=yes
LogDriver=passthrough
Network=none
@ -180,7 +182,7 @@ EOF
run_podman container inspect --format "{{.State.Status}}" $QUADLET_CONTAINER_NAME
is "$output" "running" "container should be started by systemd and hence be running"
service_cleanup $QUADLET_SERVICE_NAME failed
service_cleanup $QUADLET_SERVICE_NAME inactive
}
@test "quadlet conflict names" {
@ -1433,8 +1435,11 @@ EOF
cat > $quadlet_container_file <<EOF
[Container]
Image=$IMAGE
Exec=sh -c "echo STARTED CONTAINER; echo "READY=1" | socat -u STDIN unix-sendto:\$NOTIFY_SOCKET; sleep inf"
# Note it is important that the trap is before the ready message,
# otherwise the signal handler may not registered in time before we do systemctl stop.
Exec=sh -c "echo STARTED CONTAINER; trap 'exit' SIGTERM; echo "READY=1" | socat -u STDIN unix-sendto:\$NOTIFY_SOCKET; while :; do sleep 0.1; done"
Pod=$quadlet_pod_unit
Notify=yes
EOF
# Use the same directory for all quadlet files to make sure later steps access previous ones
@ -1467,7 +1472,7 @@ EOF
# The service of the container should be active
run systemctl show --property=ActiveState "$container_service"
assert "ActiveState=failed" \
assert "ActiveState=inactive" \
"quadlet - pod base: container service ActiveState"
# Container should not exist

View File

@ -308,10 +308,10 @@ load helpers.network
$IMAGE /bin/busybox-extras httpd -f -p 80
cid=$output
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").IPAddress}}"
ip1="$output"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").MacAddress}}"
mac1="$output"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").IPAddress}}
{{(index .NetworkSettings.Networks \"$netname\").MacAddress}}"
ip1="${lines[0]}"
mac1="${lines[1]}"
# Verify http contents: curl from localhost
run curl -s -S $SERVER/index.txt
@ -326,9 +326,9 @@ load helpers.network
fi
run iptables -t nat -F "$chain"
# check that we cannot curl (timeout after 5 sec)
run timeout 5 curl -s $SERVER/index.txt
assert $status -eq 124 "curl did not time out"
# check that we cannot curl (timeout after 1 sec)
run curl --max-time 1 -s $SERVER/index.txt
assert $status -eq 28 "curl did not time out"
fi
# reload the network to recreate the iptables rules
@ -336,10 +336,10 @@ load helpers.network
is "$output" "$cid" "Output does match container ID"
# check that we still have the same mac and ip
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").IPAddress}}"
is "$output" "$ip1" "IP address changed after podman network reload"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").MacAddress}}"
is "$output" "$mac1" "MAC address changed after podman network reload"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").IPAddress}}
{{(index .NetworkSettings.Networks \"$netname\").MacAddress}}"
is "${lines[0]}" "$ip1" "IP address changed after podman network reload"
is "${lines[1]}" "$mac1" "MAC address changed after podman network reload"
# check that we can still curl
run curl -s $SERVER/index.txt
@ -353,13 +353,13 @@ load helpers.network
# connect the container to the second network
run_podman network connect $netname2 $cid
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname2\").IPAddress}}"
ip2="$output"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname2\").GlobalIPv6Address}}"
is "$output" "fd.*:.*" "IPv6 address should start with fd..."
ipv6="$output"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname2\").MacAddress}}"
mac2="$output"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname2\").IPAddress}}
{{(index .NetworkSettings.Networks \"$netname2\").GlobalIPv6Address}}
{{(index .NetworkSettings.Networks \"$netname2\").MacAddress}}"
ip2="${lines[0]}"
is "${lines[1]}" "fd.*:.*" "IPv6 address should start with fd..."
ipv6="${lines[1]}"
mac2="${lines[2]}"
# make sure --all is working and that this
# cmd also works if the iptables still exists
@ -367,16 +367,18 @@ load helpers.network
is "$output" "$cid" "Output does match container ID"
# check that both network keep there ip and mac
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").IPAddress}}"
is "$output" "$ip1" "IP address changed after podman network reload ($netname)"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").MacAddress}}"
is "$output" "$mac1" "MAC address changed after podman network reload ($netname)"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname2\").IPAddress}}"
is "$output" "$ip2" "IP address changed after podman network reload ($netname2)"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname2\").GlobalIPv6Address}}"
is "$output" "$ipv6" "IPv6 address changed after podman network reload ($netname2)"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname2\").MacAddress}}"
is "$output" "$mac2" "MAC address changed after podman network reload ($netname2)"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").IPAddress}}
{{(index .NetworkSettings.Networks \"$netname\").MacAddress}}
{{(index .NetworkSettings.Networks \"$netname2\").IPAddress}}
{{(index .NetworkSettings.Networks \"$netname2\").GlobalIPv6Address}}
{{(index .NetworkSettings.Networks \"$netname2\").MacAddress}}
"
is "${lines[0]}" "$ip1" "IP address changed after podman network reload ($netname)"
is "${lines[1]}" "$mac1" "MAC address changed after podman network reload ($netname)"
is "${lines[2]}" "$ip2" "IP address changed after podman network reload ($netname2)"
is "${lines[3]}" "$ipv6" "IPv6 address changed after podman network reload ($netname2)"
is "${lines[4]}" "$mac2" "MAC address changed after podman network reload ($netname2)"
# check that we can still curl
run curl -s -S $SERVER/index.txt
@ -478,7 +480,7 @@ load helpers.network
run_podman network create $netname2
is "$output" "$netname2" "output of 'network create'"
# First, run a container in background to ensure that the rootless cni ns
# First, run a container in background to ensure that the rootless netns
# is not destroyed after network disconnect.
run_podman run -d --network $netname $IMAGE top
background_cid=$output
@ -498,14 +500,14 @@ load helpers.network
run curl --retry 2 --retry-connrefused -s $SERVER/index.txt
is "$output" "$random_1" "curl $SERVER/index.txt"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").IPAddress}}"
ip="$output"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").MacAddress}}"
mac="$output"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").IPAddress}}
{{(index .NetworkSettings.Networks \"$netname\").MacAddress}}
{{(index .NetworkSettings.Networks \"$netname\").Aliases}}"
ip="${lines[0]}"
mac="${lines[1]}"
# check network alias for container short id
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").Aliases}}"
is "$output" "[${cid:0:12} $hostname]" "short container id and hostname in network aliases"
is "${lines[2]}" "[${cid:0:12} $hostname]" "short container id and hostname in network aliases"
# check /etc/hosts for our entry
run_podman exec $cid cat /etc/hosts
@ -533,13 +535,12 @@ load helpers.network
# check that we have a new ip and mac
# if the ip is still the same this whole test turns into a nop
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").IPAddress}}"
new_ip="$output"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").IPAddress}}
{{(index .NetworkSettings.Networks \"$netname\").MacAddress}}"
new_ip="${lines[0]}"
assert "$new_ip" != "$ip" \
"IP address did not change after podman network disconnect/connect"
run_podman inspect $cid --format "{{(index .NetworkSettings.Networks \"$netname\").MacAddress}}"
assert "$output" != "$mac" \
assert "${lines[1]}" != "$mac" \
"MAC address did not change after podman network disconnect/connect"
# check /etc/hosts for the new entry
@ -552,14 +553,6 @@ load helpers.network
run_podman network connect $netname $background_cid
is "$output" "" "(re)connect of container with no open ports"
# FIXME FIXME FIXME: #11825: bodhi tests are failing, remote+rootless only,
# with "dnsmasq: failed to create inotify". This error has never occurred
# in CI, and Ed has been unable to reproduce it on 1minutetip. This next
# line is a suggestion from Paul Holzinger for trying to shed light on
# the system context before the failure. This output will be invisible
# if the test passes.
for foo in /proc/\*/fd/*; do readlink -f $foo; done |grep '^/proc/.*inotify' |cut -d/ -f3 | xargs -I '{}' -- ps --no-headers -o '%p %U %a' -p '{}' |uniq -c |sort -n
# connect a second network
run_podman network connect $netname2 $cid
is "$output" "" "Output should be empty (no errors)"