network_create: find free subnet automatically

Try multiple subnet numbers until successfully creating a network. This
way we can run the same ttcn3 testsuite multiple times in parallel
without conflicts (e.g. once against latest, once against nightly). Also
we don't need to make sure each new testsuite has a unique subnet
number anymore.

I've considered also adjusting network_bridge_create, but that gets used
exclusively by osmo-ran/jenkins.sh, a script which we don't actually run
in jenkins. It seems that in this script it makes more sense to not get
a random subnet number.

Related: OS#5802
Change-Id: I57152b08ef0f38e17e7019a8df032189b03f56cf
This commit is contained in:
Oliver Smith 2022-12-21 19:05:32 +01:00 committed by osmith
parent 4cb0fac1b0
commit f997b4e771
37 changed files with 156 additions and 96 deletions

View File

@ -195,8 +195,9 @@ network_clean() {
docker network inspect $NET_NAME | grep Name | cut -d : -f2 | awk -F\" 'NR>1{print $2}' | xargs -rn1 docker kill
}
# Create network and find a free subnet automatically. The global variable
# SUBNET gets set to the subnet number that has been used.
network_create() {
NET=$1
if docker network ls | grep -q $NET_NAME; then
set +x
echo "Removing stale network and containers..."
@ -204,12 +205,33 @@ network_create() {
network_clean
network_remove
fi
SUB4="172.18.$NET.0/24"
SUB6="fd02:db8:$NET::/64"
SUBNET="$PPID"
for i in $(seq 1 30); do
SUBNET="$(echo "($SUBNET + 1) % 256" | bc)"
SUB4="172.18.$SUBNET.0/24"
SUB6="fd02:db8:$SUBNET::/64"
set +x
echo "Creating network $NET_NAME, trying SUBNET=$SUBNET..."
set -x
if docker network create \
--internal \
--subnet "$SUB4" \
--ipv6 \
--subnet "$SUB6" \
"$NET_NAME"; then
set +x
echo
echo "### Network $NET_NAME created (SUBNET=$SUBNET) ###"
echo
set -x
return
fi
done
set +x
echo "Creating network $NET_NAME"
set -x
docker network create --internal --subnet $SUB4 --ipv6 --subnet $SUB6 $NET_NAME
echo "ERROR: failed to create docker network"
exit 1
}
network_bridge_create() {
@ -241,8 +263,40 @@ network_remove() {
docker network remove $NET_NAME
}
network_replace_subnet_in_configs() {
set +x
local i
local files="$(find \
"$VOL_BASE_DIR" \
-name '*.cfg' -o \
-name '*.conf' -o \
-name '*.sh' -o \
-name '*.txt' -o \
-name '*.yaml' \
)"
if [ -z "$files" ]; then
echo "ERROR: network_replace_subnet_in_configs:" \
"no config files found!"
exit 1
fi
for i in $files; do
echo "Applying SUBNET=$SUBNET to: $i"
sed \
-i \
-E \
-e "s/172\.18\.[0-9]{1,3}\./172.18.$SUBNET./g" \
-e "s/fd02:db8:[0-9]{1,3}:/fd02:db8:$SUBNET:/g" \
"$i"
done
set -x
}
# Generates list of params to pass to "docker run" to configure IP addresses
# $1: SUBNET to use, same as passed to network_create()
# $1: SUBNET to use, same as set by network_create()
# $2: Address suffix from SUBNET to apply to the container
docker_network_params() {
NET=$1

View File

@ -18,8 +18,8 @@ cp m3ua-param-testtool.scm all-sgp-tests.txt $VOL_BASE_DIR/m3ua-tester/
mkdir $VOL_BASE_DIR/stp
cp osmo-stp.cfg $VOL_BASE_DIR/stp/
SUBNET=7
network_create $SUBNET
network_create
network_replace_subnet_in_configs
# start container with STP in background
docker run --rm \

View File

@ -18,8 +18,8 @@ cp sua-param-testtool-sgp.scm some-sua-sgp-tests.txt $VOL_BASE_DIR/sua-tester/
mkdir $VOL_BASE_DIR/stp
cp osmo-stp.cfg $VOL_BASE_DIR/stp/
SUBNET=6
network_create $SUBNET
network_create
network_replace_subnet_in_configs
# start container with STP in background
docker run --rm \

View File

@ -72,15 +72,15 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=50
network_create $SUBNET
mkdir $VOL_BASE_DIR/ogt-slave
cp osmo-gsm-tester-slave.sh $VOL_BASE_DIR/ogt-slave/
mkdir $VOL_BASE_DIR/ogt-master
cp osmo-gsm-tester-master.sh $VOL_BASE_DIR/ogt-master/
network_create
network_replace_subnet_in_configs
echo Starting container with osmo-gsm-tester slave
docker run --rm \
--cap-add=NET_ADMIN \

View File

@ -21,8 +21,7 @@ fi
docker_images_require \
"$NAME-$IMAGE_SUFFIX"
SUBNET=16
network_create "$SUBNET"
network_create
container_create() {
CONTAINERNAME=$1

View File

@ -23,8 +23,8 @@ cp osmo-bsc.cfg $VOL_BASE_DIR/bsc/
mkdir $VOL_BASE_DIR/bts-omldummy
SUBNET=31
network_create $SUBNET
network_create
network_replace_subnet_in_configs
echo Starting container with STP
docker run --rm \

View File

@ -22,8 +22,8 @@ cp sccplite/osmo-bsc.cfg $VOL_BASE_DIR/bsc/
mkdir $VOL_BASE_DIR/bts-omldummy
SUBNET=12
network_create $SUBNET
network_create
network_replace_subnet_in_configs
echo Starting container with BSC
docker run --rm \

View File

@ -23,8 +23,8 @@ cp osmo-bsc.cfg $VOL_BASE_DIR/bsc/
mkdir $VOL_BASE_DIR/bts-omldummy
SUBNET=2
network_create $SUBNET
network_create
network_replace_subnet_in_configs
echo Starting container with STP
docker run --rm \

View File

@ -17,8 +17,8 @@ mkdir $VOL_BASE_DIR/bscnat
cp osmo-bsc-nat.cfg $VOL_BASE_DIR/bscnat/
cp bscs.config $VOL_BASE_DIR/bscnat/
SUBNET=15
network_create $SUBNET
network_create
network_replace_subnet_in_configs
echo Starting container with BSCNAT
docker run --rm \

View File

@ -121,8 +121,7 @@ start_testsuite() {
$REPO_USER/ttcn3-bts-test
}
SUBNET=9
network_create $SUBNET
network_create
mkdir $VOL_BASE_DIR/bts-tester-generic
cp generic/BTS_Tests.cfg $VOL_BASE_DIR/bts-tester-generic/
@ -162,6 +161,7 @@ mkdir $VOL_BASE_DIR/trxcon
mkdir $VOL_BASE_DIR/virtphy
# 1) classic test suite with BSC for OML and trxcon+fake_trx
network_replace_subnet_in_configs
start_bsc
start_bts trx 1
start_fake_trx
@ -180,6 +180,7 @@ if ! image_suffix_is_master; then
sed -i "/^ logging level osmux info/d" $VOL_BASE_DIR/bts/osmo-bts.gen.cfg
sed -i "/^ osmux/{N;N;N;N;d;}" $VOL_BASE_DIR/bts/osmo-bts.gen.cfg
fi
network_replace_subnet_in_configs
start_bts virtual 0
start_virtphy
# ... and execute the testsuite again with different cfg
@ -197,6 +198,7 @@ if ! image_suffix_is_master; then
sed -i "/^ logging level osmux info/d" $VOL_BASE_DIR/bts/osmo-bts.gen.cfg
sed -i "/^ osmux/{N;N;N;N;d;}" $VOL_BASE_DIR/bts/osmo-bts.gen.cfg
fi
network_replace_subnet_in_configs
start_bts trx 1
start_fake_trx
start_trxcon
@ -213,6 +215,7 @@ if ! image_suffix_is_master; then
fi
# restart the BSC/BTS and run the testsuite again
docker container kill ${BUILD_TAG}-bts
network_replace_subnet_in_configs
start_bsc
start_bts trx 1
start_testsuite hopping

View File

@ -16,8 +16,8 @@ write_mp_osmo_repo "$VOL_BASE_DIR/cbc-tester/CBC_Tests.cfg"
mkdir $VOL_BASE_DIR/cbc
cp osmo-cbc.cfg $VOL_BASE_DIR/cbc/
SUBNET=27
network_create $SUBNET
network_create
network_replace_subnet_in_configs
echo Starting container with CBC
docker run --rm \

View File

@ -18,9 +18,6 @@ clean_up() {
docker container rm ${BUILD_TAG}-frnet ${BUILD_TAG}-ttcn3-fr-test
}
SUBNET=26
network_create $SUBNET
mkdir $VOL_BASE_DIR/fr-tester
# if we don't change permissions, dumpcap fails to write (despite starting it as root!)
chmod a+w $VOL_BASE_DIR/fr-tester
@ -33,6 +30,9 @@ cp FRNET_Tests.cfg $VOL_BASE_DIR/frnet/
mkdir $VOL_BASE_DIR/unix
network_create
network_replace_subnet_in_configs
echo Starting container with FRNET
docker run \
`# --rm is done in clean_up()` \

View File

@ -22,9 +22,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=25
network_create $SUBNET
mkdir $VOL_BASE_DIR/gbproxy-tester
# if we don't change permissions, dumpcap fails to write (despite starting it as root!)
chmod a+w $VOL_BASE_DIR/gbproxy-tester
@ -36,6 +33,9 @@ cp osmo-gbproxy.cfg $VOL_BASE_DIR/gbproxy/
mkdir $VOL_BASE_DIR/unix
network_create
network_replace_subnet_in_configs
echo Starting container with gbproxy
docker run --rm \
--cap-add=NET_RAW --cap-add=SYS_RAWIO \

View File

@ -9,9 +9,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=24
network_create $SUBNET
mkdir $VOL_BASE_DIR/gbproxy-tester
# if we don't change permissions, dumpcap fails to write (despite starting it as root!)
chmod a+w $VOL_BASE_DIR/gbproxy-tester
@ -24,6 +21,9 @@ cp osmo-gbproxy.cfg $VOL_BASE_DIR/gbproxy/
mkdir $VOL_BASE_DIR/unix
network_create
network_replace_subnet_in_configs
echo Starting container with gbproxy
docker run --rm \
$(docker_network_params $SUBNET 10) \

View File

@ -24,8 +24,8 @@ cp ogs/freediameter.conf $VOL_BASE_DIR/ggsn/
cp ogs/upfd.sh $VOL_BASE_DIR/ggsn/
cp ogs/upfd-setup.sh $VOL_BASE_DIR/ggsn/
SUBNET=3
network_create $SUBNET
network_create
network_replace_subnet_in_configs
# start container with ggsn (smf+upf) in background
docker run --cap-add=NET_ADMIN \

View File

@ -23,8 +23,7 @@ write_mp_osmo_repo "$VOL_BASE_DIR/ggsn-tester/GGSN_Tests.cfg"
mkdir $VOL_BASE_DIR/ggsn
SUBNET=3
network_create $SUBNET
network_create
# start container with ggsn in background
GGSN_CMD="osmo-ggsn -c /data/osmo-ggsn.cfg"
@ -32,6 +31,7 @@ GGSN_DOCKER_ARGS=""
if [ "$KERNEL_TEST" = "1" ]; then
cp osmo-ggsn-kernel-gtp.cfg $VOL_BASE_DIR/ggsn/osmo-ggsn.cfg
cp initrd-ggsn.sh $VOL_BASE_DIR/ggsn/
network_replace_subnet_in_configs
kernel_test_prepare \
"defconfig" \
@ -50,6 +50,7 @@ if [ "$KERNEL_TEST" = "1" ]; then
OSMO_SUT_HOST="172.18.$SUBNET.200"
else
cp osmo-ggsn.cfg $VOL_BASE_DIR/ggsn/
network_replace_subnet_in_configs
GGSN_DOCKER_ARGS="
$(docker_network_params $SUBNET 201)

View File

@ -9,9 +9,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=10
network_create $SUBNET
mkdir $VOL_BASE_DIR/hlr-tester
cp HLR_Tests.cfg $VOL_BASE_DIR/hlr-tester/
write_mp_osmo_repo "$VOL_BASE_DIR/hlr-tester/HLR_Tests.cfg"
@ -19,6 +16,9 @@ write_mp_osmo_repo "$VOL_BASE_DIR/hlr-tester/HLR_Tests.cfg"
mkdir $VOL_BASE_DIR/hlr
cp osmo-hlr.cfg $VOL_BASE_DIR/hlr/
network_create
network_replace_subnet_in_configs
echo Starting container with HLR
docker run --rm \
$(docker_network_params $SUBNET 20) \

View File

@ -19,8 +19,7 @@ clean_up() {
$VOL_BASE_DIR_PFCP/hnbgw-tester/junit-xml-with-pfcp-*.log
}
SUBNET=35
network_create $SUBNET
network_create
run_tests() {
base_dir="$1"
@ -42,6 +41,8 @@ run_tests() {
mkdir $base_dir/unix
network_replace_subnet_in_configs
echo Starting container with STP
docker run --rm \
$(docker_network_params $SUBNET 200) \

View File

@ -20,8 +20,8 @@ cp osmo-hnodeb.cfg $VOL_BASE_DIR/hnodeb/
mkdir $VOL_BASE_DIR/unix
SUBNET=33
network_create $SUBNET
network_create
network_replace_subnet_in_configs
echo Starting container with HNodeB
docker run --rm \

View File

@ -20,8 +20,8 @@ if ! image_suffix_is_master; then
sed -i "/^ osmux bind-ip-v6 fd02:db8:4::180/d" $VOL_BASE_DIR/mgw/osmo-mgw.cfg
fi
SUBNET=4
network_create $SUBNET
network_create
network_replace_subnet_in_configs
# start container with mgw in background
docker run --rm \

View File

@ -10,9 +10,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=20
network_create $SUBNET
mkdir $VOL_BASE_DIR/msc-tester
mkdir $VOL_BASE_DIR/msc-tester/unix
cp MSC_Tests.cfg $VOL_BASE_DIR/msc-tester/
@ -27,6 +24,9 @@ cp osmo-msc.cfg $VOL_BASE_DIR/msc/
mkdir $VOL_BASE_DIR/unix
network_create
network_replace_subnet_in_configs
echo Starting container with STP
docker run --rm \
$(docker_network_params $SUBNET 200) \

View File

@ -19,8 +19,8 @@ clean_up() {
docker container stop -t 0 ${BUILD_TAG}-sysinfo-helper
}
SUBNET=5
network_create $SUBNET
network_create
network_replace_subnet_in_configs
# start container with nitb in background
docker volume rm nitb-vol

View File

@ -22,9 +22,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=30
network_create $SUBNET
mkdir $VOL_BASE_DIR/ns-tester
cp fr/NS_Tests.cfg $VOL_BASE_DIR/ns-tester/
write_mp_osmo_repo "$VOL_BASE_DIR/ns-tester/NS_Tests.cfg"
@ -32,6 +29,9 @@ write_mp_osmo_repo "$VOL_BASE_DIR/ns-tester/NS_Tests.cfg"
mkdir $VOL_BASE_DIR/ns
cp fr/osmo-ns-dummy.cfg $VOL_BASE_DIR/ns/
network_create
network_replace_subnet_in_configs
echo Starting container with osmo-ns-dummy
docker run --rm \
--cap-add=NET_RAW --cap-add=SYS_RAWIO \

View File

@ -9,9 +9,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=32
network_create $SUBNET
mkdir $VOL_BASE_DIR/ns-tester
cp sgsn-sns/NS_Tests.cfg $VOL_BASE_DIR/ns-tester/
write_mp_osmo_repo "$VOL_BASE_DIR/ns-tester/NS_Tests.cfg"
@ -19,6 +16,9 @@ write_mp_osmo_repo "$VOL_BASE_DIR/ns-tester/NS_Tests.cfg"
mkdir $VOL_BASE_DIR/ns
cp sgsn-sns/osmo-ns-dummy.cfg $VOL_BASE_DIR/ns/
network_create
network_replace_subnet_in_configs
echo Starting container with osmo-ns-dummy
docker run --rm \
$(docker_network_params $SUBNET 101) \

View File

@ -9,9 +9,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=29
network_create $SUBNET
mkdir $VOL_BASE_DIR/ns-tester
cp sns/NS_Tests.cfg $VOL_BASE_DIR/ns-tester/
write_mp_osmo_repo "$VOL_BASE_DIR/ns-tester/NS_Tests.cfg"
@ -19,6 +16,9 @@ write_mp_osmo_repo "$VOL_BASE_DIR/ns-tester/NS_Tests.cfg"
mkdir $VOL_BASE_DIR/ns
cp sns/osmo-ns-dummy.cfg $VOL_BASE_DIR/ns/
network_create
network_replace_subnet_in_configs
echo Starting container with osmo-ns-dummy
docker run --rm \
$(docker_network_params $SUBNET 101) \

View File

@ -9,9 +9,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=28
network_create $SUBNET
mkdir $VOL_BASE_DIR/ns-tester
cp NS_Tests.cfg $VOL_BASE_DIR/ns-tester/
write_mp_osmo_repo "$VOL_BASE_DIR/ns-tester/NS_Tests.cfg"
@ -19,6 +16,9 @@ write_mp_osmo_repo "$VOL_BASE_DIR/ns-tester/NS_Tests.cfg"
mkdir $VOL_BASE_DIR/ns
cp osmo-ns-dummy.cfg $VOL_BASE_DIR/ns/
network_create
network_replace_subnet_in_configs
echo Starting container with osmo-ns-dummy
docker run --rm \
$(docker_network_params $SUBNET 101) \

View File

@ -16,8 +16,8 @@ write_mp_osmo_repo "$VOL_BASE_DIR/pcap-client-tester/OPCAP_CLIENT_Tests.cfg"
mkdir $VOL_BASE_DIR/pcap-client
cp osmo-pcap-client.cfg $VOL_BASE_DIR/pcap-client/
SUBNET=31
network_create $SUBNET
network_create
network_replace_subnet_in_configs
echo Starting container with pcap-client
docker run --rm \

View File

@ -9,9 +9,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=14
network_create $SUBNET
mkdir $VOL_BASE_DIR/pcu-tester
mkdir $VOL_BASE_DIR/pcu-tester/unix
cp sns/PCU_Tests.cfg $VOL_BASE_DIR/pcu-tester/
@ -23,6 +20,9 @@ cp sns/osmo-pcu.cfg $VOL_BASE_DIR/pcu/
mkdir $VOL_BASE_DIR/unix
network_create
network_replace_subnet_in_configs
echo Starting container with PCU
docker run --rm \
$(docker_network_params $SUBNET 101) \

View File

@ -9,9 +9,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=13
network_create $SUBNET
mkdir $VOL_BASE_DIR/pcu-tester
mkdir $VOL_BASE_DIR/pcu-tester/unix
cp PCU_Tests.cfg $VOL_BASE_DIR/pcu-tester/
@ -23,6 +20,9 @@ cp osmo-pcu.cfg $VOL_BASE_DIR/pcu/
mkdir $VOL_BASE_DIR/unix
network_create
network_replace_subnet_in_configs
echo Starting container with PCU
docker run --rm \
$(docker_network_params $SUBNET 101) \

View File

@ -19,8 +19,8 @@ cp open5gs-*.yaml $VOL_BASE_DIR/pgw/
cp upfd.sh $VOL_BASE_DIR/pgw/
cp upfd-setup.sh $VOL_BASE_DIR/pgw/
SUBNET=18
network_create $SUBNET
network_create
network_replace_subnet_in_configs
# start container with open5gs-nrfd in background
docker run --rm \

View File

@ -62,8 +62,7 @@ start_testsuite() {
$REPO_USER/ttcn3-remsim-test
}
SUBNET=17
network_create $SUBNET
network_create
mkdir $VOL_BASE_DIR/remsim-tester
@ -76,23 +75,26 @@ mkdir $VOL_BASE_DIR/client
# 1) server test suite
start_server
cp REMSIM_Tests.cfg $VOL_BASE_DIR/remsim-tester/
write_mp_osmo_repo "$VOL_BASE_DIR/remsim-tester/REMSIM_Tests.cfg"
network_replace_subnet_in_configs
start_server
start_testsuite
docker container kill ${BUILD_TAG}-server
# 2) bankd test suite
echo "Changing to bankd configuration"
start_bankd
cp bankd/REMSIM_Tests.cfg $VOL_BASE_DIR/remsim-tester/
write_mp_osmo_repo "$VOL_BASE_DIR/remsim-tester/REMSIM_Tests.cfg"
network_replace_subnet_in_configs
start_bankd
start_testsuite
docker container kill ${BUILD_TAG}-bankd
# 3) client test suite
echo "Changing to client configuration"
start_client
cp client/REMSIM_Tests.cfg $VOL_BASE_DIR/remsim-tester/
write_mp_osmo_repo "$VOL_BASE_DIR/remsim-tester/REMSIM_Tests.cfg"
network_replace_subnet_in_configs
start_client
start_testsuite

View File

@ -17,8 +17,8 @@ write_mp_osmo_repo "$VOL_BASE_DIR/sccp-tester/SCCP_Tests.cfg"
mkdir $VOL_BASE_DIR/sccp
cp sccp_demo_user.cfg $VOL_BASE_DIR/sccp/
SUBNET=22
network_create $SUBNET
network_create
network_replace_subnet_in_configs
echo Starting container with sccp_demo_user
docker run --rm \

View File

@ -10,9 +10,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=8
network_create $SUBNET
mkdir $VOL_BASE_DIR/sgsn-tester
cp SGSN_Tests.cfg $VOL_BASE_DIR/sgsn-tester/
write_mp_osmo_repo "$VOL_BASE_DIR/sgsn-tester/SGSN_Tests.cfg"
@ -25,6 +22,9 @@ cp osmo-stp.cfg $VOL_BASE_DIR/stp/
mkdir $VOL_BASE_DIR/unix
network_create
network_replace_subnet_in_configs
echo Starting container with STP
docker run --rm \
$(docker_network_params $SUBNET 200) \

View File

@ -9,9 +9,6 @@ docker_images_require \
set_clean_up_trap
set -e
SUBNET=11
network_create $SUBNET
mkdir $VOL_BASE_DIR/sip-tester
mkdir $VOL_BASE_DIR/sip-tester/unix
cp SIP_Tests.cfg $VOL_BASE_DIR/sip-tester/
@ -23,6 +20,9 @@ cp osmo-sip-connector.cfg $VOL_BASE_DIR/sip/
mkdir $VOL_BASE_DIR/unix
network_create
network_replace_subnet_in_configs
echo Starting container with osmo-sip-connector
docker run --rm \
$(docker_network_params $SUBNET 10) \

View File

@ -20,8 +20,8 @@ cp osmo-stp.cfg $VOL_BASE_DIR/stp/
mkdir $VOL_BASE_DIR/smlc
cp osmo-smlc.cfg $VOL_BASE_DIR/smlc/
SUBNET=23
network_create $SUBNET
network_create
network_replace_subnet_in_configs
echo Starting container with STP
docker run --rm \

View File

@ -16,8 +16,8 @@ write_mp_osmo_repo "$VOL_BASE_DIR/stp-tester/STP_Tests.cfg"
mkdir $VOL_BASE_DIR/stp
cp osmo-stp.cfg $VOL_BASE_DIR/stp/
SUBNET=19
network_create $SUBNET
network_create
network_replace_subnet_in_configs
echo Starting container with STP
docker run --rm \

View File

@ -16,8 +16,8 @@ write_mp_osmo_repo "$VOL_BASE_DIR/upf-tester/UPF_Tests.cfg"
mkdir $VOL_BASE_DIR/upf
cp osmo-upf.cfg $VOL_BASE_DIR/upf/
SUBNET=34
network_create $SUBNET
network_create
network_replace_subnet_in_configs
echo Starting container with UPF
docker run --rm \