You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcpcfg/testsuite/ngcp-network

156 lines
5.9 KiB

#!/bin/bash
# defaults
if [ -d local ] ; then # running with carton
CMD="perl -Ilocal/lib/perl5 -CSD ../sbin/ngcp-network"
else
CMD="perl -CSD ../sbin/ngcp-network"
fi
count=0
RC=0
OUTPUT=$(mktemp) || exit 1
# generated files
rm -rf testfiles
mkdir testfiles
bailout() {
rm -f "$OUTPUT"
}
trap bailout 1 2 3 3 6 9 14 15
OK() {
printf "ok %s %s\n" "$1" "$2"
}
FAIL() {
printf "not ok %s %s\n" "$1" "$2"
RC=1
}
assertEqualFiles() {
[ "$#" -eq 2 ] || return 1
(( count++ ))
if cmp "$1" "$2" 2>/dev/null ; then
OK "$count" "$2" >> "$OUTPUT"
else
echo "files $1 and $2 do not match" >&2
diff -u "$1" "$2" >&2
FAIL "$count" "$2 # $2 differs from $1" >> "$OUTPUT"
return 1
fi
}
# make sure ip/netmask/interface can be set on existing host
${CMD} --input-file=network-config/network_pro.yml --output-file=testfiles/eth42.yml \
--host=sp1 --set-interface=eth42 --ip=1.2.3.4 --netmask=255.255.255.248
assertEqualFiles testfiles/eth42.yml network-config/eth42.yml
# test IPv4/IPv6 with many options
cp network-config/network_pro.yml testfiles/eth46.yml
${CMD} --input-file=testfiles/eth46.yml --output-file=testfiles/eth46.yml \
--host=sp1 --set-interface=eth46 \
--hwaddr c0:ff:ee:15:90:0d \
--ip=127.11.22.33 --netmask=255.0.0.0 --gateway 127.11.22.254 \
--ipv6 2001:aaaa:1111:bbbb:2222:cccc:3333:dddd --netmask-ipv6 64 --gateway-ipv6 2001:aaaa:1111:bbbb:2222:cccc:3333:0001 \
--dns 127.0.0.1 --dns 1.1.1.1 --dns ::1 --dns 2606:4700:4700::1111
${CMD} --input-file=testfiles/eth46.yml --output-file=testfiles/eth46.yml \
--host=sp1 --set-interface=bond0 \
--bond-mode active-backup --bond-miimon '100' --bond-slaves 'eth11 eth22' \
--ip 10.10.10.2 --netmask 255.0.0.0 --gateway 10.10.10.254
${CMD} --input-file=testfiles/eth46.yml --output-file=testfiles/eth46.yml \
--host=sp1 --set-interface=eth11 \
--hwaddr 11:11:11:11:11:11 --mtu 1111 \
--dhcp yes
${CMD} --input-file=testfiles/eth46.yml --output-file=testfiles/eth46.yml \
--host=sp1 --set-interface=eth22 \
--hwaddr 22:22:22:22:22:22 --mtu 2222 \
--dhcp yes
${CMD} --input-file=testfiles/eth46.yml --output-file=testfiles/eth46.yml \
--host=sp1 --set-interface=vlan1111 \
--vlan-raw-device bond0 \
--ip 10.11.11.11 --netmask 255.0.0.0 --gateway 10.11.11.254
${CMD} --input-file=testfiles/eth46.yml --output-file=testfiles/eth46.yml \
--host=sp1 --set-interface=vlan2222 \
--vlan-raw-device bond0 \
--ip 10.22.22.22 --netmask 255.0.0.0 --gateway 10.22.22.254
${CMD} --input-file=testfiles/eth46.yml --output-file=testfiles/eth46.yml \
--host=sp1 --set-interface=vlan3333 \
--vlan-raw-device bond0 \
--ip 10.33.33.33 --netmask 255.0.0.0 --gateway 10.33.33.254
assertEqualFiles testfiles/eth46.yml network-config/eth46.yml
# verify deployment steps
ROLE=sp1; PEER=sp2; DEFAULT_INSTALL_DEV=eth0; INTERNAL_DEV=eth1;
in_counter=1; out_counter=1 # do not hardcode input/output files
${CMD} --host=$ROLE --set-interface=lo --ip=127.0.0.1 --netmask=255.0.0.0 \
--hwaddr=00:00:00:00:00:00 --ipv6='::1' --type=web_int \
--input-file=network-config/network_pro.yml --output-file=testfiles/deploy_${out_counter}.yml
((out_counter++))
${CMD} --host=$ROLE --set-interface=lo --shared-ip=none --shared-ipv6=none \
--input-file=testfiles/deploy_${in_counter}.yml --output-file=testfiles/deploy_${out_counter}.yml
((out_counter++)) ; ((in_counter++))
${CMD} --host=$ROLE --set-interface=$DEFAULT_INSTALL_DEV --ip=1.2.3.4 \
--netmask=255.255.255.0 --hwaddr=de:ad:be:ef:23:42 --dns=2.3.4.5 --dns=3.4.5.6 \
--gateway=1.2.3.1 \
--input-file=testfiles/deploy_${in_counter}.yml --output-file=testfiles/deploy_${out_counter}.yml
((out_counter++)) ; ((in_counter++))
${CMD} --host=$ROLE --set-interface=$INTERNAL_DEV --ip=192.168.255.251 \
--netmask=255.255.255.248 --hwaddr=de:ad:be:ef:42:23 \
--input-file=testfiles/deploy_${in_counter}.yml --output-file=testfiles/deploy_${out_counter}.yml
((out_counter++)) ; ((in_counter++))
${CMD} --host=$ROLE --peer=$PEER \
--input-file=testfiles/deploy_${in_counter}.yml --output-file=testfiles/deploy_${out_counter}.yml
((out_counter++)) ; ((in_counter++))
${CMD} --host=$ROLE --move-from=lo --move-to=$INTERNAL_DEV --type=ha_int \
--input-file=testfiles/deploy_${in_counter}.yml --output-file=testfiles/deploy_${out_counter}.yml
((out_counter++)) ; ((in_counter++))
${CMD} --host=$PEER --peer=$ROLE \
--input-file=testfiles/deploy_${in_counter}.yml --output-file=testfiles/deploy_${out_counter}.yml
((out_counter++)) ; ((in_counter++))
${CMD} --host=$PEER --set-interface=lo --shared-ip=none --shared-ipv6=none \
--input-file=testfiles/deploy_${in_counter}.yml --output-file=testfiles/deploy_${out_counter}.yml
((out_counter++)) ; ((in_counter++))
${CMD} --host=$PEER --set-interface=lo --ipv6='::1' --ip=127.0.0.1 --netmask=255.0.0.0 --hwaddr=00:00:00:00:00:00 \
--input-file=testfiles/deploy_${in_counter}.yml --output-file=testfiles/deploy_${out_counter}.yml
((out_counter++)) ; ((in_counter++))
${CMD} --host=$PEER --set-interface=eth1 --ip=192.168.255.252 --netmask=255.255.255.248 --type=ha_int \
--input-file=testfiles/deploy_${in_counter}.yml --output-file=testfiles/deploy_${out_counter}.yml
((out_counter++)) ; ((in_counter++))
${CMD} --host=$PEER --role=proxy --role=lb --role=mgmt \
--input-file=testfiles/deploy_${in_counter}.yml --output-file=testfiles/deploy_${out_counter}.yml
((out_counter++)) ; ((in_counter++))
${CMD} --host=$PEER --set-interface=lo --type=sip_int --type=web_ext --type=sip_ext \
--type=rtp_ext --type=ssh_ext --type=mon_ext --type=web_int \
--input-file=testfiles/deploy_${in_counter}.yml --output-file=testfiles/deployment.yml
assertEqualFiles testfiles/deployment.yml network-config/deployment.yml
# TAP output
printf "1..%s\n" "${count}"
cat "$OUTPUT"
bailout
exit $RC