From 8bab3e2e1fdaf1f6275763a8a17a96ccfd07be27 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Sat, 31 Oct 2026 14:15:17 +0100 Subject: [PATCH] =?UTF-8?q?f-90:=20e2e:=2029,=20=C3=A9tat=20de=20l'h=C3=B4?= =?UTF-8?q?te=20et=20nettoyage=20lus=20en=20nftables=20#90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: GnomeZworc --- test/e2e/lib/fixture.sh | 3 ++- test/e2e/suite/29-dns-ntp.sh | 18 ++++++++++-------- test/e2e/suite/61-redemarrage-agent.sh | 2 +- test/e2e/suite/62-nettoyage-global.sh | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/test/e2e/lib/fixture.sh b/test/e2e/lib/fixture.sh index b160501..9a381c2 100644 --- a/test/e2e/lib/fixture.sh +++ b/test/e2e/lib/fixture.sh @@ -56,7 +56,8 @@ host_state () { echo "## adresses"; ip -o -4 addr show | awk '{print $2, $4}' | sort echo "## routes"; ip -4 route show table all | grep -v '^local \|^broadcast ' | sort echo "## nftables bridge"; nft list ruleset bridge - echo "## iptables"; iptables-save | grep -v '^#' | sed 's/ \[[0-9]*:[0-9]*\]$//' + echo "## nftables ip"; nft list ruleset ip + echo "## nftables des netns"; local ns; for ns in $(ip netns list | awk '{print $1}' | sort); do echo "# ${ns}"; ip netns exec "${ns}" nft list ruleset; done echo "## frr"; vtysh -c 'show running-config' | grep -v '^Building\|^Current configuration\|^!' echo "## frr.conf"; sha256sum /etc/frr/frr.conf | cut -d' ' -f1 echo "## fichiers"; find /run/two /etc/dnsmasq.d "${VOLUMES}" -mindepth 1 ! -type d 2>/dev/null | sort diff --git a/test/e2e/suite/29-dns-ntp.sh b/test/e2e/suite/29-dns-ntp.sh index ebeac52..941fe83 100644 --- a/test/e2e/suite/29-dns-ntp.sh +++ b/test/e2e/suite/29-dns-ntp.sh @@ -50,9 +50,9 @@ ntp_ok () { } no_answer () { ! vm_py "${1}" "${2}" dns_py "${3}" udp deb.debian.org "${4}" >/dev/null 2>&1; } served_ports () { ip netns exec "${1}" ss -Hlntu | awk '$5 ~ /^169\.254\.169\.253:/ {print $1, $5}' | sort | tr '\n' ' '; } -rules () { ip netns exec "${1}" iptables -t nat -S TWO-HOSTSVC; } +rules () { ip netns exec "${1}" nft list chain ip two hostsvc | sed -n '/^\t\t/s/^\t\t//p'; } state_has () { grep -q "\"${1}\"" /run/two/hostsvc/hostsvc.state; } -excluded_first () { [ "$(rules "${1}" | sed -n '2p;3p' | tr '\n' ' ')" = "-A TWO-HOSTSVC -i br-public -j RETURN -A TWO-HOSTSVC -i l3-+ -j RETURN " ]; } +excluded_first () { [ "$(rules "${1}" | sed -n '2p;3p' | tr '\n' ' ')" = 'iifname "br-public" return iifname "l3-*" return ' ]; } no_dns () { ! dns_ok "$@" >/dev/null 2>&1; } no_ntp () { ! ntp_ok "$@" >/dev/null 2>&1; } vpc_in_error () { @@ -71,9 +71,10 @@ check "subnet sn-t29b en mode bridge sur br-lan, interface_ip 10.33.0.29" subnet for vpc in vp-t29 vp-t29b; do check "${vpc} : 169.254.169.253 sur la dummy hostsvc" sh -c "ip -n ${vpc} -4 -o addr show dev hostsvc | grep -q ' 169.254.169.253/32 '" check "${vpc} : two-hostsvc n'écoute que 53/udp, 53/tcp et 123/udp sur 169.254.169.253" test "$(served_ports "${vpc}")" = "tcp 169.254.169.253:53 udp 169.254.169.253:123 udp 169.254.169.253:53 " - check "${vpc} : chaîne TWO-HOSTSVC, br-public et l3-+ exclus avant toute redirection" excluded_first "${vpc}" - check "${vpc} : redirection de 53/udp, 53/tcp et 123/udp vers 169.254.169.253" test "$(rules "${vpc}" | grep -c 'DNAT --to-destination 169.254.169.253')" -eq 3 - check "${vpc} : appel depuis PREROUTING pour les destinations locales seulement" sh -c "ip netns exec ${vpc} iptables -t nat -S PREROUTING | grep -qx -- '-A PREROUTING -m addrtype --dst-type LOCAL -j TWO-HOSTSVC'" + check "${vpc} : chaîne hostsvc de ip two accrochée à prerouting en dstnat" test "$(rules "${vpc}" | head -n 1)" = "type nat hook prerouting priority dstnat; policy accept;" + check "${vpc} : br-public et l3-* exclus avant toute redirection" excluded_first "${vpc}" + check "${vpc} : redirection de 53/udp, 53/tcp et 123/udp vers 169.254.169.253" test "$(rules "${vpc}" | grep -c 'dnat to 169.254.169.253$')" -eq 3 + check "${vpc} : redirection pour les destinations locales seulement" test "$(rules "${vpc}" | grep -c '^fib daddr type local .* dnat to 169.254.169.253$')" -eq 3 check "${vpc} : inscrit dans l'état de two-hostsvc" state_has "${vpc}" done @@ -98,10 +99,11 @@ ip -n vp-t29 addr del 169.254.169.253/32 dev hostsvc check "watchdog : adresse 169.254.169.253 retirée signalée" wait_watchdog "169.254.169.253 missing on hostsvc (in netns)" ip -n vp-t29 addr add 169.254.169.253/32 dev hostsvc check "10.29.1.10 : DNS de nouveau servi une fois l'adresse remise" dns_ok vp-t29 10.29.1.10 10.29.1.254 udp -ip netns exec vp-t29 iptables -t nat -D TWO-HOSTSVC -p udp -m udp --dport 123 -j DNAT --to-destination 169.254.169.253 -check "watchdog : redirection incomplète signalée" wait_watchdog "dns and ntp redirection to 169.254.169.253 missing or incomplete (chain TWO-HOSTSVC)" +HANDLE=$(ip netns exec vp-t29 nft -a list chain ip two hostsvc | awk '/udp dport 123 / {print $NF}') +check "règle 123 retirée à la main de hostsvc (handle ${HANDLE:-absent})" ip netns exec vp-t29 nft delete rule ip two hostsvc handle "${HANDLE}" +check "watchdog : redirection incomplète signalée" wait_watchdog "dns and ntp redirection to 169.254.169.253 missing or incomplete (nft chain ip two hostsvc)" check "10.29.1.10 : sans la règle 123, plus de NTP (témoin)" no_ntp vp-t29 10.29.1.10 10.29.1.254 -ip netns exec vp-t29 iptables -t nat -A TWO-HOSTSVC -p udp -m udp --dport 123 -j DNAT --to-destination 169.254.169.253 +check "règle 123 reposée" ip netns exec vp-t29 nft add rule ip two hostsvc fib daddr type local udp dport 123 dnat to 169.254.169.253 check "10.29.1.10 : NTP de nouveau servi une fois la règle remise" ntp_ok vp-t29 10.29.1.10 10.29.1.254 systemctl stop two-hostsvc.service diff --git a/test/e2e/suite/61-redemarrage-agent.sh b/test/e2e/suite/61-redemarrage-agent.sh index f161674..93dcd01 100644 --- a/test/e2e/suite/61-redemarrage-agent.sh +++ b/test/e2e/suite/61-redemarrage-agent.sh @@ -48,7 +48,7 @@ sleep 20 check "après redémarrage : même processus QEMU pour t61-a (ni arrêtée ni recréée)" test "$(pgrep -f "${VOLUMES}/t61-a.qcow2" | sort | tr '\n' ' ')" = "${QEMU}" check "après redémarrage : même processus QEMU pour t61-d" test "$(pgrep -f "${VOLUMES}/t61-d.qcow2" | sort | tr '\n' ' ')" = "${QEMU_D}" check "après redémarrage : mêmes fichiers sous /run/two, /etc/dnsmasq.d et les volumes (sinon, fichiers en cause)" section_unchanged "${STATE_DIR}/t61.restart" fichiers -check "après redémarrage : hôte inchangé (netns, liens, taps, adresses, routes, nftables de pont, iptables, FRR, frr.conf, fichiers, unités)" same_as "${STATE_DIR}/t61.restart" host_state +check "après redémarrage : hôte inchangé (netns, liens, taps, adresses, routes, nftables de pont, ip et des netns, FRR, frr.conf, fichiers, unités)" same_as "${STATE_DIR}/t61.restart" host_state check "après redémarrage : l'API rend les mêmes ressources dans le même état" same_as "${STATE_DIR}/t61.api" api_snapshot for rr in 10.255.255.1 10.255.255.2; do check "après redémarrage : session EVPN vers ${rr} établie, jamais coupée" sh -c "vtysh -c 'show bgp neighbors ${rr}' | grep -q 'BGP state = Established' && [ \"\$(vtysh -c 'show bgp neighbors ${rr}' | grep -o 'dropped [0-9]*')\" = \"\$(cat '${STATE_DIR}/t61.${rr}')\" ]" diff --git a/test/e2e/suite/62-nettoyage-global.sh b/test/e2e/suite/62-nettoyage-global.sh index 5bea382..02912aa 100644 --- a/test/e2e/suite/62-nettoyage-global.sh +++ b/test/e2e/suite/62-nettoyage-global.sh @@ -18,7 +18,7 @@ check "${HOST} : aucune instance DHCP (dhcp@, dnsmasq@) ni de métadonnées (met check "${HOST} : aucun socket de contrôle DHCP" none sh -c "ls /run/two/dhcp/*.sock 2>/dev/null" check "${HOST} : aucun processus QEMU" none pgrep -a qemu-system check "${HOST} : aucune règle nftables de pont qui vise une interface de subnet" none sh -c "nft list ruleset bridge | grep -E 'v-[a-z0-9]'" -check "${HOST} : aucune règle iptables qui vise une interface de subnet ou de VPC" none sh -c "iptables-save | grep -E -- '(v-|vp-|tap)[a-z0-9]'" +check "${HOST} : aucune règle nftables ip qui vise une interface de subnet ou de VPC" none sh -c "nft list ruleset ip | grep -E -- '(v-|vp-|tap)[a-z0-9]'" check "${HOST} : aucun volume de VM de test" none sh -c "ls '${VOLUMES}'/t[0-9][0-9]-* 2>/dev/null" check "${HOST} : FRR garde la base BGP (témoin)" sh -c "vtysh -c 'show running-config' | grep -q 'peer-group fabric'" check "${HOST} : FRR sans aucune VRF de VPC (en mémoire)" none sh -c "vtysh -c 'show running-config' | grep -E '^(vrf |router bgp [0-9]+ vrf )'"