From 2bf6ec7d1a9601b49bcbc75f9cfc82208aea389d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= Date: Wed, 28 Feb 2024 16:46:47 +0100 Subject: [PATCH] test: ipv4_autoconf: Fix racecondition on slow test-PCs Refactor test, remove fragile solution with tcpdump started AFTER the linklocal was activated, this opened for a race condition since it was listening for a message sent once. Now wait for the linklocal address instead. --- test/case/infix_interfaces/ipv4_autoconf.py | 33 ++++++++++----------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/test/case/infix_interfaces/ipv4_autoconf.py b/test/case/infix_interfaces/ipv4_autoconf.py index 936281a9..1ae21639 100755 --- a/test/case/infix_interfaces/ipv4_autoconf.py +++ b/test/case/infix_interfaces/ipv4_autoconf.py @@ -4,6 +4,19 @@ # import infamy +import time +import infamy.iface + +from infamy.util import until + +def has_linklocal(target, iface): + """Check if interface as a linklocal address""" + addrs = infamy.iface.get_ipv4_address(target, iface) + if not addrs: + return False + for addr in addrs: + if addr['origin'] == "random": + return True with infamy.Test() as test: with test.step("Initialize"): @@ -29,23 +42,7 @@ with infamy.Test() as test: } }) - with test.step("Wait for mDNS message from a 169.254 address ..."): - _, hport = env.ltop.xlate("host", "data") - - with infamy.IsolatedMacVlan(hport) as ns: - vrfy = ns.runsh(""" - set -ex - - ip link set iface up - ip addr add 10.0.0.1/24 dev iface - - fakeroot tcpdump -q -i iface -c 1 -n host 224.0.0.251 and port 5353 --print 2>/dev/null \ - | awk 'match($0,/169\\.254\\.[0-9]+\\.[0-9]+/) {print substr($0,RSTART,RLENGTH)}' \ - | grep . || exit 1 - """) - - if vrfy.returncode: - print(vrfy.stdout) - test.fail() + with test.step("Wait for linklocal address on interface"): + until(lambda: has_linklocal(target, tport), attempts=10) test.succeed()