58 lines
2.5 KiB
Bash
58 lines
2.5 KiB
Bash
#!/bin/sh
|
|||
|
|
# Офлайн-проверка шаблонов роли frr_anycast для окружения site_cloud (4 узла,
|
||
|
|
# 2 канала, as-path prepend только на резервном, sNAT). Golden-файлов для
|
||
|
|
# этого окружения нет (оно новое, живых ВМ нет) — проверяем grep'ом ожидаемые
|
||
|
|
# инварианты вместо byte-diff.
|
||
|
|
set -e
|
||
|
|
cd "$(dirname "$0")/.." # -> ansible/
|
||
|
|
|
||
|
|
ENV_FILE="${SITE_ENV_FILE:-site-cloud.env}"
|
||
|
|
if [ ! -f "$ENV_FILE" ]; then
|
||
|
|
echo "Не найден файл переменных окружения: $ENV_FILE" >&2
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
set -a
|
||
|
|
# shellcheck disable=SC1090
|
||
|
|
. "./$ENV_FILE"
|
||
|
|
set +a
|
||
|
|
|
||
|
|
OUT_DIR="$(mktemp -d)"
|
||
|
|
trap 'rm -rf "$OUT_DIR"' EXIT
|
||
|
|
|
||
|
|
ansible-playbook -i inventory/site-cloud.yml tests/render-test-cloud.yml -e "render_out_dir=$OUT_DIR" 2>&1 | cat
|
||
|
|
|
||
|
|
STATUS=0
|
||
|
|
check() {
|
||
|
|
# check <label> <file> <pattern> <expected_count>
|
||
|
|
label="$1"; file="$2"; pattern="$3"; expected="$4"
|
||
|
|
actual="$(grep -Fc -- "$pattern" "$file" || true)"
|
||
|
|
if [ "$actual" = "$expected" ]; then
|
||
|
|
echo "OK $label ($file): '$pattern' x$expected"
|
||
|
|
else
|
||
|
|
echo "FAIL $label ($file): ожидалось '$pattern' x$expected, найдено x$actual" >&2
|
||
|
|
STATUS=1
|
||
|
|
fi
|
||
|
|
}
|
||
|
|
|
||
|
|
for n in vr01 vr02 vr03 vr04; do
|
||
|
|
f="$OUT_DIR/$n/frr.conf"
|
||
|
|
check "$n router bgp" "$f" "router bgp 65200" 1
|
||
|
|
check "$n network anycast" "$f" " network 172.31.255.10/32" 1
|
||
|
|
check "$n neighbor main1" "$f" " neighbor $MAIN1_NEIGHBOR_IP remote-as 65104" 1
|
||
|
|
check "$n neighbor main2" "$f" " neighbor $MAIN2_NEIGHBOR_IP remote-as 65104" 1
|
||
|
|
check "$n neighbor backup1" "$f" " neighbor $BACKUP1_NEIGHBOR_IP remote-as 65103" 1
|
||
|
|
check "$n neighbor backup2" "$f" " neighbor $BACKUP2_NEIGHBOR_IP remote-as 65103" 1
|
||
|
|
check "$n route-map defined" "$f" "route-map RM-PREPEND-OUT permit 10" 1
|
||
|
|
check "$n prepend value" "$f" "set as-path prepend 65200 65200 65200" 1
|
||
|
|
check "$n route-map on backup1 only" "$f" "neighbor $BACKUP1_NEIGHBOR_IP route-map RM-PREPEND-OUT out" 1
|
||
|
|
check "$n route-map on backup2 only" "$f" "neighbor $BACKUP2_NEIGHBOR_IP route-map RM-PREPEND-OUT out" 1
|
||
|
|
check "$n NO route-map on main1" "$f" "neighbor $MAIN1_NEIGHBOR_IP route-map RM-PREPEND-OUT out" 0
|
||
|
|
check "$n NO route-map on main2" "$f" "neighbor $MAIN2_NEIGHBOR_IP route-map RM-PREPEND-OUT out" 0
|
||
|
|
|
||
|
|
nft="$OUT_DIR/$n/nftables.conf"
|
||
|
|
check "$n nftables masquerade" "$nft" "masquerade" 1
|
||
|
|
check "$n nftables oifname" "$nft" "oifname \"$EXT_IFACE\"" 1
|
||
|
|
done
|
||
|
|
|
||
|
|
exit "$STATUS"
|