mirror of
https://github.com/project-zot/zot.git
synced 2026-06-17 21:17:58 +08:00
636a6b1820
Changes in this PR ================== - Replaces the get_free_port bash function in BATS tests with get_free_port_for_service that returns a random free port in a given range for a test file and service defined in a ports.json file. - Updates all get_free_port calls to use the new function. - A new README file for details on the ports.json file. - Updates some tests using fixed ports to use dynamic ports. - Adds a ports.json file with all the allocations. - Adds a new common helper for port fetching. Signed-off-by: Vishwas Rajashekar <30438425+vrajashkr@users.noreply.github.com>
80 lines
1.8 KiB
Bash
80 lines
1.8 KiB
Bash
HAPROXY_CFG_FILE="${BATS_FILE_TMPDIR}/haproxy/haproxy-test.cfg"
|
|
|
|
function generate_haproxy_server_list() {
|
|
local num_instances=${1}
|
|
shift
|
|
local ports=("$@")
|
|
|
|
for ((i=0;i<${num_instances};i++)) do
|
|
local port=${ports[$i]}
|
|
echo " server zot${i} 127.0.0.1:${port}"
|
|
done
|
|
}
|
|
|
|
# stops all haproxy instances started by the test
|
|
function haproxy_stop_all() {
|
|
pkill haproxy
|
|
}
|
|
|
|
# starts one haproxy instance with the given config file
|
|
# expects the haproxy config to specify daemon mode
|
|
function haproxy_start() {
|
|
local haproxy_cfg_file=${1}
|
|
|
|
# Check the config file
|
|
haproxy -f ${haproxy_cfg_file} -c >&3
|
|
|
|
# Start haproxy
|
|
haproxy -f ${haproxy_cfg_file}
|
|
}
|
|
|
|
# generates HAproxy config for use in the test
|
|
function generate_haproxy_config() {
|
|
local haproxy_cfg_file="${1}"
|
|
shift
|
|
local haproxy_root_dir="$(dirname ${haproxy_cfg_file})"
|
|
# can be either http or https
|
|
local protocol="${1}"
|
|
shift
|
|
local haproxy_port="${1}"
|
|
shift
|
|
local zot_ports=("$@")
|
|
|
|
mkdir -p ${haproxy_root_dir}
|
|
|
|
local haproxy_mode='http'
|
|
if [ "$protocol" == 'https' ]; then
|
|
haproxy_mode='tcp'
|
|
fi
|
|
|
|
cat > ${haproxy_cfg_file}<<EOF
|
|
global
|
|
log ${haproxy_root_dir}/log local0
|
|
log ${haproxy_root_dir}/log local1 notice
|
|
maxconn 20000
|
|
stats timeout 30s
|
|
daemon
|
|
|
|
defaults
|
|
log global
|
|
mode ${haproxy_mode}
|
|
option ${haproxy_mode}log
|
|
option dontlognull
|
|
timeout connect 5000
|
|
timeout client 50000
|
|
timeout server 50000
|
|
|
|
frontend zot
|
|
bind *:${haproxy_port}
|
|
default_backend zot-cluster
|
|
|
|
backend zot-cluster
|
|
balance roundrobin
|
|
EOF
|
|
|
|
# Populate server list
|
|
generate_haproxy_server_list ${NUM_ZOT_INSTANCES} "${zot_ports[@]}" >> ${haproxy_cfg_file}
|
|
|
|
cat ${haproxy_cfg_file} >&3
|
|
}
|