summaryrefslogtreecommitdiff
path: root/test/system/helpers.bash
diff options
context:
space:
mode:
authorEd Santiago <santiago@redhat.com>2022-07-07 08:02:53 -0600
committerEd Santiago <santiago@redhat.com>2022-07-07 09:42:05 -0600
commite8d2d70ee2ee9307c929793df50a56e9f54dcb57 (patch)
tree9b4bfac27b947c4cd374271d630fb43c20dfaeaa /test/system/helpers.bash
parentdd0418a5fe0c44d4358b0118bd2a9847d78a80a2 (diff)
downloadpodman-e8d2d70ee2ee9307c929793df50a56e9f54dcb57.tar.gz
podman-e8d2d70ee2ee9307c929793df50a56e9f54dcb57.tar.bz2
podman-e8d2d70ee2ee9307c929793df50a56e9f54dcb57.zip
port forward range test: fix many oopses
Wrong variable. And, wrong index range. And, wrong bash syntax for extracting end_port. And, add explicit check for valid range, because die() inside 'foo=$(...)' will not actually die. And, refactor some confusing code. And, reformat/clean up a confusing and too-wide comment. Fixes: #14854 Signed-off-by: Ed Santiago <santiago@redhat.com>
Diffstat (limited to 'test/system/helpers.bash')
-rw-r--r--test/system/helpers.bash14
1 files changed, 8 insertions, 6 deletions
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