From: Yu Watanabe Date: Thu, 26 Jun 2025 21:23:09 +0000 (+0900) Subject: test-network: wait for all addresses and routes configured before start monitoring X-Git-Tag: v258-rc1~240 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d63c8ce020e553b355025c40e8ef725abcadf604;p=thirdparty%2Fsystemd.git test-network: wait for all addresses and routes configured before start monitoring Otherwise, kernel may announce configuration of an address or route after 'ip monitor' is started. This also makes the test check if the whole output of 'ip monitor' is empty. Otherwise, if the test fails, it is hard to find what is wrong. Follow-ups for 912a48572de1411cff2964452e0d7a021b43921f and bcb9e72b6bf57d6d2aec581fedc4a33d6d826e2f. Fixes #37982. --- diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 710d94b4634..3aa288e6e9e 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -5161,6 +5161,18 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities): call('ip -4 addr add 10.20.30.40/32 dev unmanaged0') call('ip -6 addr add 2001:db8:9999:f101::15/64 dev unmanaged0') + # Wait for all addresses + self.wait_address('unmanaged0', 'inet 10.20.30.40/32', scope='global', ipv='-4', timeout_sec=10) + self.wait_address('unmanaged0', 'inet6 2001:db8:9999:f101::15/64', scope='global', ipv='-6', timeout_sec=10) + self.wait_address('unmanaged0', 'inet6 fe80::[0-9a-f:]*/64', scope='link', ipv='-6', timeout_sec=10) + + # Wait for all routes + self.wait_route('unmanaged0', 'local 10.20.30.40 proto kernel', table='local', ipv='-4', timeout_sec=10) + self.wait_route('unmanaged0', 'local fe80::[0-9a-f:]* proto kernel', table='local', ipv='-6', timeout_sec=10) + self.wait_route('unmanaged0', 'multicast ff00::/8 proto kernel', table='local', ipv='-6', timeout_sec=10) + self.wait_route('unmanaged0', '2001:db8:9999:f101::/64 proto kernel', table='main', ipv='-6', timeout_sec=10) + self.wait_route('unmanaged0', 'fe80::/64 proto kernel', table='main', ipv='-6', timeout_sec=10) + # Start `ip monitor` with output to a temporary file with tempfile.TemporaryFile(mode='r+', prefix='ip_monitor_u') as logfile_unmanaged: process_u = subprocess.Popen(['ip', 'monitor', 'dev', 'unmanaged0'], stdout=logfile_unmanaged, text=True) @@ -5200,13 +5212,9 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities): print('### ip monitor dev unmanaged0 BEGIN') - # Read the `ip monitor` output looking for network changes + # Read the `ip monitor` output looking for network changes and check if something happened logfile_unmanaged.seek(0) - for line in logfile_unmanaged: - line = line.rstrip() - print(line) - # Check if something happened - self.assertEqual(line, '') + self.assertEqual(logfile_unmanaged.read().rstrip(), '') print('### ip monitor dev unmanaged0 END')