mirror of https://github.com/containers/podman.git
Merge pull request #11486 from edsantiago/bats
system tests: new random_free_port helper
This commit is contained in:
commit
26c8549ae3
|
|
@ -22,12 +22,7 @@ fi
|
||||||
|
|
||||||
# Randomly-assigned port in the 5xxx range
|
# Randomly-assigned port in the 5xxx range
|
||||||
if [ -z "${PODMAN_LOGIN_REGISTRY_PORT}" ]; then
|
if [ -z "${PODMAN_LOGIN_REGISTRY_PORT}" ]; then
|
||||||
for port in $(shuf -i 5000-5999);do
|
export PODMAN_LOGIN_REGISTRY_PORT=$(random_free_port)
|
||||||
if ! { exec 3<> /dev/tcp/127.0.0.1/$port; } &>/dev/null; then
|
|
||||||
export PODMAN_LOGIN_REGISTRY_PORT=$port
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Override any user-set path to an auth file
|
# Override any user-set path to an auth file
|
||||||
|
|
|
||||||
|
|
@ -76,11 +76,7 @@ function teardown() {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Randomly-assigned port in the 5xxx range
|
# Randomly-assigned port in the 5xxx range
|
||||||
for port in $(shuf -i 5000-5999);do
|
port=$(random_free_port)
|
||||||
if ! { exec 3<> /dev/tcp/127.0.0.1/$port; } &>/dev/null; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Listener. This will exit as soon as it receives a message.
|
# Listener. This will exit as soon as it receives a message.
|
||||||
run_podman run -d --pod $podname $IMAGE nc -l -p $port
|
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
|
pod_id_file=${PODMAN_TMPDIR}/pod-id-file
|
||||||
|
|
||||||
# Randomly-assigned ports in the 5xxx and 6xxx range
|
# Randomly-assigned ports in the 5xxx and 6xxx range
|
||||||
for port_in in $(shuf -i 5000-5999);do
|
port_in=$(random_free_port 5000-5999)
|
||||||
if ! { exec 3<> /dev/tcp/127.0.0.1/$port_in; } &>/dev/null; then
|
port_out=$(random_free_port 6000-6999)
|
||||||
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
|
|
||||||
|
|
||||||
# Create a pod with all the desired options
|
# Create a pod with all the desired options
|
||||||
# FIXME: --ip=$ip fails:
|
# FIXME: --ip=$ip fails:
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ SOCKET_FILE="$UNIT_DIR/$SERVICE_NAME.socket"
|
||||||
|
|
||||||
@test "podman system service - tcp CORS" {
|
@test "podman system service - tcp CORS" {
|
||||||
skip_if_remote "system service tests are meaningless over remote"
|
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 &
|
run_podman system service --cors="*" tcp:$SERVICE_TCP_HOST:$PORT -t 20 &
|
||||||
podman_pid="$!"
|
podman_pid="$!"
|
||||||
sleep 5s
|
sleep 5s
|
||||||
|
|
@ -26,7 +26,7 @@ SOCKET_FILE="$UNIT_DIR/$SERVICE_NAME.socket"
|
||||||
|
|
||||||
@test "podman system service - tcp without CORS" {
|
@test "podman system service - tcp without CORS" {
|
||||||
skip_if_remote "system service tests are meaningless over remote"
|
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 &
|
run_podman system service tcp:$SERVICE_TCP_HOST:$PORT -t 20 &
|
||||||
podman_pid="$!"
|
podman_pid="$!"
|
||||||
sleep 5s
|
sleep 5s
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ load helpers
|
||||||
random_1=$(random_string 30)
|
random_1=$(random_string 30)
|
||||||
random_2=$(random_string 30)
|
random_2=$(random_string 30)
|
||||||
|
|
||||||
HOST_PORT=8080
|
HOST_PORT=$(random_free_port)
|
||||||
SERVER=http://127.0.0.1:$HOST_PORT
|
SERVER=http://127.0.0.1:$HOST_PORT
|
||||||
|
|
||||||
# Create a test file with random content
|
# 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
|
# Issue #5466 - port-forwarding doesn't work with this option and -d
|
||||||
@test "podman networking: port with --userns=keep-id" {
|
@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
|
for cidr in "" "$(random_rfc1918_subnet).0/24"; do
|
||||||
myport=$(( myport + 1 ))
|
myport=$(random_free_port 52000-52999)
|
||||||
if [[ -z $cidr ]]; then
|
if [[ -z $cidr ]]; then
|
||||||
# regex to match that we are in 10.X subnet
|
# regex to match that we are in 10.X subnet
|
||||||
match="10\..*"
|
match="10\..*"
|
||||||
|
|
@ -188,6 +185,7 @@ load helpers
|
||||||
|
|
||||||
# "network create" now works rootless, with the help of a special container
|
# "network create" now works rootless, with the help of a special container
|
||||||
@test "podman network create" {
|
@test "podman network create" {
|
||||||
|
# Deliberately use a fixed port, not random_open_port, because of #10806
|
||||||
myport=54322
|
myport=54322
|
||||||
|
|
||||||
local mynetname=testnet-$(random_string 10)
|
local mynetname=testnet-$(random_string 10)
|
||||||
|
|
@ -244,7 +242,7 @@ load helpers
|
||||||
skip_if_remote "podman network reload does not have remote support"
|
skip_if_remote "podman network reload does not have remote support"
|
||||||
|
|
||||||
random_1=$(random_string 30)
|
random_1=$(random_string 30)
|
||||||
HOST_PORT=12345
|
HOST_PORT=$(random_free_port)
|
||||||
SERVER=http://127.0.0.1:$HOST_PORT
|
SERVER=http://127.0.0.1:$HOST_PORT
|
||||||
|
|
||||||
# Create a test file with random content
|
# Create a test file with random content
|
||||||
|
|
@ -396,7 +394,7 @@ load helpers
|
||||||
# Test for https://github.com/containers/podman/issues/10052
|
# Test for https://github.com/containers/podman/issues/10052
|
||||||
@test "podman network connect/disconnect with port forwarding" {
|
@test "podman network connect/disconnect with port forwarding" {
|
||||||
random_1=$(random_string 30)
|
random_1=$(random_string 30)
|
||||||
HOST_PORT=12345
|
HOST_PORT=$(random_free_port)
|
||||||
SERVER=http://127.0.0.1:$HOST_PORT
|
SERVER=http://127.0.0.1:$HOST_PORT
|
||||||
|
|
||||||
# Create a test file with random content
|
# Create a test file with random content
|
||||||
|
|
|
||||||
|
|
@ -278,6 +278,23 @@ function wait_for_ready {
|
||||||
wait_for_output '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
|
# wait_for_port # Returns once port is available on host
|
||||||
###################
|
###################
|
||||||
|
|
@ -288,7 +305,7 @@ function wait_for_port() {
|
||||||
|
|
||||||
# Wait
|
# Wait
|
||||||
while [ $_timeout -gt 0 ]; do
|
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
|
sleep 1
|
||||||
_timeout=$(( $_timeout - 1 ))
|
_timeout=$(( $_timeout - 1 ))
|
||||||
done
|
done
|
||||||
|
|
|
||||||
|
|
@ -213,8 +213,16 @@ declare -a lines=(
|
||||||
)
|
)
|
||||||
check_same_dev "zero-line output"
|
check_same_dev "zero-line output"
|
||||||
|
|
||||||
|
|
||||||
# END remove_same_dev_warning
|
# 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
|
exit $rc
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue