aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoropenshift-ci[bot] <75433959+openshift-ci[bot]@users.noreply.github.com>2022-07-07 17:42:38 +0000
committerGitHub <noreply@github.com>2022-07-07 17:42:38 +0000
commit41ac2cfb1976c9ca793fd29ac1a4099ced27bbee (patch)
tree681b46606c7c2fa303e829abdc150cd557c7823b /test
parentd52ac4422b1b8f959e411b13680e7fb40880a939 (diff)
parente8d2d70ee2ee9307c929793df50a56e9f54dcb57 (diff)
downloadpodman-41ac2cfb1976c9ca793fd29ac1a4099ced27bbee.tar.gz
podman-41ac2cfb1976c9ca793fd29ac1a4099ced27bbee.tar.bz2
podman-41ac2cfb1976c9ca793fd29ac1a4099ced27bbee.zip
Merge pull request #14855 from edsantiago/port_forward_duh
port forward range test: fix an oops
Diffstat (limited to 'test')
-rw-r--r--test/system/500-networking.bats12
-rw-r--r--test/system/helpers.bash14
2 files changed, 16 insertions, 10 deletions
diff --git a/test/system/500-networking.bats b/test/system/500-networking.bats
index 0d724985e..50eb15216 100644
--- a/test/system/500-networking.bats
+++ b/test/system/500-networking.bats
@@ -677,16 +677,20 @@ EOF
@test "podman run port forward range" {
for netmode in bridge slirp4netns:port_handler=slirp4netns slirp4netns:port_handler=rootlesskit; do
local range=$(random_free_port_range 3)
- local port="${test%-*}"
- local end_port="${test#-*}"
+ # die() inside $(...) does not actually stop us.
+ assert "$range" != "" "Could not find free port range"
+
+ local port="${range%-*}"
+ local end_port="${range#*-}"
local random=$(random_string)
run_podman run --network $netmode -p "$range:$range" -d $IMAGE sleep inf
cid="$output"
for port in $(seq $port $end_port); do
run_podman exec -d $cid nc -l -p $port -e /bin/cat
- # -w 1 adds a 1 second timeout, for some reason ubuntus ncat doesn't close the connection on EOF,
- # other options to change this are not portable across distros but -w seems to work
+ # -w 1 adds a 1 second timeout. For some reason, ubuntu's ncat
+ # doesn't close the connection on EOF, and other options to
+ # change this are not portable across distros. -w seems to work.
run nc -w 1 127.0.0.1 $port <<<$random
is "$output" "$random" "ncat got data back (netmode=$netmode port=$port)"
done
diff --git a/test/system/helpers.bash b/test/system/helpers.bash
index 273e8d2f5..ceac48036 100644
--- a/test/system/helpers.bash
+++ b/test/system/helpers.bash
@@ -299,15 +299,17 @@ function random_free_port_range() {
local maxtries=10
while [[ $maxtries -gt 0 ]]; do
local firstport=$(random_free_port)
- local all_ports_free=1
- for i in $(seq 2 $size); do
- if ! port_is_free $((firstport + $i)); then
- all_ports_free=
+ local lastport=
+ for i in $(seq 1 $((size - 1))); do
+ lastport=$((firstport + i))
+ if ! port_is_free $lastport; then
+ echo "# port $lastport is in use; trying another." >&3
+ lastport=
break
fi
done
- if [[ -n "$all_ports_free" ]]; then
- echo "$firstport-$((firstport + $size - 1))"
+ if [[ -n "$lastport" ]]; then
+ echo "$firstport-$lastport"
return
fi