diff options
Diffstat (limited to 'test/system')
-rw-r--r-- | test/system/005-info.bats | 1 | ||||
-rw-r--r-- | test/system/035-logs.bats | 27 | ||||
-rw-r--r-- | test/system/070-build.bats | 27 | ||||
-rw-r--r-- | test/system/075-exec.bats | 28 | ||||
-rw-r--r-- | test/system/150-login.bats | 7 | ||||
-rw-r--r-- | test/system/200-pod.bats | 18 | ||||
-rw-r--r-- | test/system/250-systemd.bats | 23 | ||||
-rw-r--r-- | test/system/255-auto-update.bats | 6 | ||||
-rw-r--r-- | test/system/271-tcp-cors-server.bats | 4 | ||||
-rw-r--r-- | test/system/500-networking.bats | 12 | ||||
-rw-r--r-- | test/system/700-play.bats | 10 | ||||
-rw-r--r-- | test/system/helpers.bash | 19 | ||||
-rwxr-xr-x | test/system/helpers.t | 10 |
13 files changed, 159 insertions, 33 deletions
diff --git a/test/system/005-info.bats b/test/system/005-info.bats index 96ca2c1bd..0ea0f8356 100644 --- a/test/system/005-info.bats +++ b/test/system/005-info.bats @@ -9,6 +9,7 @@ load helpers buildahVersion: *[0-9.]\\\+ conmon:\\\s\\\+package: distribution: +logDriver: ociRuntime:\\\s\\\+name: os: rootless: diff --git a/test/system/035-logs.bats b/test/system/035-logs.bats index 32282c8e1..a04d2ac74 100644 --- a/test/system/035-logs.bats +++ b/test/system/035-logs.bats @@ -174,4 +174,31 @@ $s_after" _log_test_until journald } +function _log_test_follow() { + local driver=$1 + cname=$(random_string) + contentA=$(random_string) + contentB=$(random_string) + contentC=$(random_string) + + # Note: it seems we need at least three log lines to hit #11461. + run_podman run --log-driver=$driver --name $cname $IMAGE sh -c "echo $contentA; echo $contentB; echo $contentC" + run_podman logs -f $cname + is "$output" "$contentA +$contentB +$contentC" "logs -f on exitted container works" + + run_podman rm -f $cname +} + +@test "podman logs - --follow k8s-file" { + _log_test_follow k8s-file +} + +@test "podman logs - --follow journald" { + # We can't use journald on RHEL as rootless: rhbz#1895105 + skip_if_journald_unavailable + + _log_test_follow journald +} # vim: filetype=sh diff --git a/test/system/070-build.bats b/test/system/070-build.bats index 0f58b2784..47db08eb1 100644 --- a/test/system/070-build.bats +++ b/test/system/070-build.bats @@ -929,6 +929,33 @@ EOF is "$output" ".*test1" "test1 should exists in the final image" } +@test "podman build build context ownership" { + tmpdir=$PODMAN_TMPDIR/build-test + subdir=$tmpdir/subdir + mkdir -p $subdir + + touch $tmpdir/empty-file.txt + if is_remote && ! is_rootless ; then + # TODO: set this file's owner to a UID:GID that will not be mapped + # in the context where the remote server is running, which generally + # requires us to be root (or running with more mapped IDs) on the + # client, but not root (or running with fewer mapped IDs) on the + # remote server + # 4294967292:4294967292 (0xfffffffc:0xfffffffc) isn't that, but + # it will catch errors where a remote server doesn't apply the right + # default as it copies content into the container + chown 4294967292:4294967292 $tmpdir/empty-file.txt + fi + cat >$tmpdir/Dockerfile <<EOF +FROM $IMAGE +COPY empty-file.txt . +RUN echo 0:0 | tee expected.txt +RUN stat -c "%u:%g" empty-file.txt | tee actual.txt +RUN cmp expected.txt actual.txt +EOF + run_podman build -t build_test $tmpdir +} + function teardown() { # A timeout or other error in 'build' can leave behind stale images # that podman can't even see and which will cascade into subsequent diff --git a/test/system/075-exec.bats b/test/system/075-exec.bats index 3e8c3c1ea..b7367d153 100644 --- a/test/system/075-exec.bats +++ b/test/system/075-exec.bats @@ -101,4 +101,32 @@ load helpers run_podman rm $cid } +# #11496: podman-remote loses output +@test "podman exec/run - missing output" { + local bigfile=${PODMAN_TMPDIR}/bigfile + local newfile=${PODMAN_TMPDIR}/newfile + # create a big file, bigger than the 8K buffer size + base64 /dev/urandom | head -c 20K > $bigfile + + run_podman run --rm -v $bigfile:/tmp/test:Z $IMAGE cat /tmp/test + printf "%s" "$output" > $newfile + # use cmp to compare the files, this is very helpful since it will + # tell us the first wrong byte in case this fails + run cmp $bigfile $newfile + is "$output" "" "run output is identical with the file" + + run_podman run -d --stop-timeout 0 -v $bigfile:/tmp/test:Z $IMAGE sleep inf + cid="$output" + + run_podman exec $cid cat /tmp/test + printf "%s" "$output" > $newfile + # use cmp to compare the files, this is very helpful since it will + # tell us the first wrong byte in case this fails + run cmp $bigfile $newfile + is "$output" "" "exec output is identical with the file" + + # Clean up + run_podman rm -f $cid +} + # vim: filetype=sh diff --git a/test/system/150-login.bats b/test/system/150-login.bats index b6c04db08..ed925044c 100644 --- a/test/system/150-login.bats +++ b/test/system/150-login.bats @@ -22,12 +22,7 @@ fi # Randomly-assigned port in the 5xxx range if [ -z "${PODMAN_LOGIN_REGISTRY_PORT}" ]; then - for port in $(shuf -i 5000-5999);do - if ! { exec 3<> /dev/tcp/127.0.0.1/$port; } &>/dev/null; then - export PODMAN_LOGIN_REGISTRY_PORT=$port - break - fi - done + export PODMAN_LOGIN_REGISTRY_PORT=$(random_free_port) fi # Override any user-set path to an auth file diff --git a/test/system/200-pod.bats b/test/system/200-pod.bats index 266f91298..027abf9dc 100644 --- a/test/system/200-pod.bats +++ b/test/system/200-pod.bats @@ -76,11 +76,7 @@ function teardown() { fi # Randomly-assigned port in the 5xxx range - for port in $(shuf -i 5000-5999);do - if ! { exec 3<> /dev/tcp/127.0.0.1/$port; } &>/dev/null; then - break - fi - done + port=$(random_free_port) # Listener. This will exit as soon as it receives a message. run_podman run -d --pod $podname $IMAGE nc -l -p $port @@ -183,16 +179,8 @@ function random_ip() { pod_id_file=${PODMAN_TMPDIR}/pod-id-file # Randomly-assigned ports in the 5xxx and 6xxx range - for port_in in $(shuf -i 5000-5999);do - if ! { exec 3<> /dev/tcp/127.0.0.1/$port_in; } &>/dev/null; then - break - fi - done - for port_out in $(shuf -i 6000-6999);do - if ! { exec 3<> /dev/tcp/127.0.0.1/$port_out; } &>/dev/null; then - break - fi - done + port_in=$(random_free_port 5000-5999) + port_out=$(random_free_port 6000-6999) # Create a pod with all the desired options # FIXME: --ip=$ip fails: diff --git a/test/system/250-systemd.bats b/test/system/250-systemd.bats index 08fad5e7c..4578d9e60 100644 --- a/test/system/250-systemd.bats +++ b/test/system/250-systemd.bats @@ -136,6 +136,29 @@ function service_cleanup() { service_cleanup } +# Regression test for #11438 +@test "podman generate systemd - restart policy" { + cname=$(random_string) + run_podman create --restart=always --name $cname $IMAGE + run_podman generate systemd --new $cname + is "$output" ".*Restart=always.*" "Use container's restart policy if set" + run_podman generate systemd --new --restart-policy=on-failure $cname + is "$output" ".*Restart=on-failure.*" "Override container's restart policy" + + cname2=$(random_string) + run_podman create --restart=unless-stopped --name $cname2 $IMAGE + run_podman generate systemd --new $cname2 + is "$output" ".*Restart=always.*" "unless-stopped translated to always" + + cname3=$(random_string) + run_podman create --restart=on-failure:42 --name $cname3 $IMAGE + run_podman generate systemd --new $cname3 + is "$output" ".*Restart=on-failure.*" "on-failure:xx is parsed correclty" + is "$output" ".*StartLimitBurst=42.*" "on-failure:xx is parsed correctly" + + run_podman rm -f $cname $cname2 $cname3 +} + function set_listen_env() { export LISTEN_PID="100" LISTEN_FDS="1" LISTEN_FDNAMES="listen_fdnames" } diff --git a/test/system/255-auto-update.bats b/test/system/255-auto-update.bats index b172bb917..bb4b5c13f 100644 --- a/test/system/255-auto-update.bats +++ b/test/system/255-auto-update.bats @@ -339,6 +339,8 @@ EOF } @test "podman auto-update using systemd" { + skip_if_journald_unavailable + generate_service alpine image cat >$UNIT_DIR/podman-auto-update-$cname.timer <<EOF @@ -386,7 +388,9 @@ EOF done if [[ -n "$failed_start" ]]; then - die "Did not find expected string '$expect' in journalctl output for $cname" + echo "journalctl output:" + sed -e 's/^/ /' <<<"$output" + die "Did not find expected string '$expect' in journalctl output for $cname" fi _confirm_update $cname $ori_image diff --git a/test/system/271-tcp-cors-server.bats b/test/system/271-tcp-cors-server.bats index cdfa82e82..d8e4eb3df 100644 --- a/test/system/271-tcp-cors-server.bats +++ b/test/system/271-tcp-cors-server.bats @@ -14,7 +14,7 @@ SOCKET_FILE="$UNIT_DIR/$SERVICE_NAME.socket" @test "podman system service - tcp CORS" { skip_if_remote "system service tests are meaningless over remote" - PORT=$(( ((RANDOM<<15)|RANDOM) % 63001 + 2000 )) + PORT=$(random_free_port 63000-64999) run_podman system service --cors="*" tcp:$SERVICE_TCP_HOST:$PORT -t 20 & podman_pid="$!" sleep 5s @@ -26,7 +26,7 @@ SOCKET_FILE="$UNIT_DIR/$SERVICE_NAME.socket" @test "podman system service - tcp without CORS" { skip_if_remote "system service tests are meaningless over remote" - PORT=$(( ((RANDOM<<15)|RANDOM) % 63001 + 2000 )) + PORT=$(random_free_port 63000-64999) run_podman system service tcp:$SERVICE_TCP_HOST:$PORT -t 20 & podman_pid="$!" sleep 5s diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats index 3ebe45e63..ad5891dd9 100644 --- a/test/system/500-networking.bats +++ b/test/system/500-networking.bats @@ -23,7 +23,7 @@ load helpers random_1=$(random_string 30) random_2=$(random_string 30) - HOST_PORT=8080 + HOST_PORT=$(random_free_port) SERVER=http://127.0.0.1:$HOST_PORT # Create a test file with random content @@ -114,11 +114,8 @@ load helpers # Issue #5466 - port-forwarding doesn't work with this option and -d @test "podman networking: port with --userns=keep-id" { - # FIXME: randomize port, and create second random host port - myport=54321 - for cidr in "" "$(random_rfc1918_subnet).0/24"; do - myport=$(( myport + 1 )) + myport=$(random_free_port 52000-52999) if [[ -z $cidr ]]; then # regex to match that we are in 10.X subnet match="10\..*" @@ -188,6 +185,7 @@ load helpers # "network create" now works rootless, with the help of a special container @test "podman network create" { + # Deliberately use a fixed port, not random_open_port, because of #10806 myport=54322 local mynetname=testnet-$(random_string 10) @@ -244,7 +242,7 @@ load helpers skip_if_remote "podman network reload does not have remote support" random_1=$(random_string 30) - HOST_PORT=12345 + HOST_PORT=$(random_free_port) SERVER=http://127.0.0.1:$HOST_PORT # Create a test file with random content @@ -396,7 +394,7 @@ load helpers # Test for https://github.com/containers/podman/issues/10052 @test "podman network connect/disconnect with port forwarding" { random_1=$(random_string 30) - HOST_PORT=12345 + HOST_PORT=$(random_free_port) SERVER=http://127.0.0.1:$HOST_PORT # Create a test file with random content diff --git a/test/system/700-play.bats b/test/system/700-play.bats index 7f35877aa..2b05cdd84 100644 --- a/test/system/700-play.bats +++ b/test/system/700-play.bats @@ -98,6 +98,16 @@ RELABEL="system_u:object_r:container_file_t:s0" run_podman 125 play kube --network host $PODMAN_TMPDIR/test.yaml is "$output" ".*invalid value passed to --network: bridge or host networking must be configured in YAML" "podman plan-network should fail with --network host" run_podman play kube --network slirp4netns:port_handler=slirp4netns $PODMAN_TMPDIR/test.yaml + run_podman pod inspect --format {{.InfraContainerID}} "${lines[1]}" + infraID="$output" + run_podman container inspect --format "{{.HostConfig.NetworkMode}}" $infraID + is "$output" "slirp4netns" "network mode slirp4netns is set for the container" + run_podman pod rm -f test_pod + run_podman play kube --network none $PODMAN_TMPDIR/test.yaml + run_podman pod inspect --format {{.InfraContainerID}} "${lines[1]}" + infraID="$output" + run_podman container inspect --format "{{.HostConfig.NetworkMode}}" $infraID + is "$output" "none" "network mode none is set for the container" run_podman pod rm -f test_pod } diff --git a/test/system/helpers.bash b/test/system/helpers.bash index bd9471ace..28ea924bb 100644 --- a/test/system/helpers.bash +++ b/test/system/helpers.bash @@ -278,6 +278,23 @@ function wait_for_ready { wait_for_output 'READY' "$@" } +###################### +# random_free_port # Pick an available port within a specified range +###################### +function random_free_port() { + local range=${1:-5000-5999} + + local port + for port in $(shuf -i ${range}); do + if ! { exec {unused_fd}<> /dev/tcp/127.0.0.1/$port; } &>/dev/null; then + echo $port + return + fi + done + + die "Could not find open port in range $range" +} + ################### # wait_for_port # Returns once port is available on host ################### @@ -288,7 +305,7 @@ function wait_for_port() { # Wait while [ $_timeout -gt 0 ]; do - { exec 5<> /dev/tcp/$host/$port; } &>/dev/null && return + { exec {unused_fd}<> /dev/tcp/$host/$port; } &>/dev/null && return sleep 1 _timeout=$(( $_timeout - 1 )) done diff --git a/test/system/helpers.t b/test/system/helpers.t index 190e8ba35..b83d9a89b 100755 --- a/test/system/helpers.t +++ b/test/system/helpers.t @@ -213,8 +213,16 @@ declare -a lines=( ) check_same_dev "zero-line output" - # END remove_same_dev_warning ############################################################################### +# BEGIN random_free_port + +# Assumes that 16700 is open +found=$(random_free_port 16700-16700) + +check_result "$found" "16700" "random_free_port" + +# END random_free_port +############################################################################### exit $rc |