From 130d66956ff7577233574fc26108dbdc4ce42d8c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 7 Nov 2024 09:52:03 +0900 Subject: [PATCH] test-network: reconfigure interface cleanly to drop previous DHCP lease and friends Follow-up for 451c2baf30f50b95d73e648058c7c2348dbf0c31. With the commits, reloading .network files does not release previously acquired DHCP lease and friends if possible. On graceful reconfigure triggered by the reload, the interface may acquire a new DHCPv4 lease earlier than DHCPv6 lease. In that case, the check will fail as it is done with the new DHCPv4 lease and old DHCPv6 lease, which does not contain any IPv6 DNS servers or so. So, when switching from no -> yes, we need to wait a new lease with DNS servers or so. To achieve that, we need to clean reconfigure the interface. --- test/test-network/systemd-networkd-tests.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 59503d31a19..111da949abe 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -7447,7 +7447,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): self.assertIn('inet 169.254.133.11/16 metric 2048 brd 169.254.255.255 scope link', output) def test_dhcp_client_use_dns(self): - def check(self, ipv4, ipv6): + def check(self, ipv4, ipv6, needs_reconfigure=False): os.makedirs(os.path.join(network_unit_dir, '25-dhcp-client.network.d'), exist_ok=True) with open(os.path.join(network_unit_dir, '25-dhcp-client.network.d/override.conf'), mode='w', encoding='utf-8') as f: f.write('[DHCPv4]\nUseDNS=') @@ -7457,6 +7457,8 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): f.write('\n[IPv6AcceptRA]\nUseDNS=no') networkctl_reload() + if needs_reconfigure: + networkctl_reconfigure('veth99') self.wait_online('veth99:routable') # link becomes 'routable' when at least one protocol provide an valid address. Hence, we need to explicitly wait for both addresses. @@ -7488,7 +7490,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): check(self, True, True) check(self, True, False) - check(self, False, True) + check(self, False, True, needs_reconfigure=True) check(self, False, False) def test_dhcp_client_default_use_domains(self): @@ -7540,7 +7542,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): check(self, False, False, False) def test_dhcp_client_use_dnr(self): - def check(self, ipv4, ipv6): + def check(self, ipv4, ipv6, needs_reconfigure=False): os.makedirs(os.path.join(network_unit_dir, '25-dhcp-client.network.d'), exist_ok=True) with open(os.path.join(network_unit_dir, '25-dhcp-client.network.d/override.conf'), mode='w', encoding='utf-8') as f: f.write('[DHCPv4]\nUseDNS=') @@ -7550,6 +7552,8 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): f.write('\n[IPv6AcceptRA]\nUseDNS=no') networkctl_reload() + if needs_reconfigure: + networkctl_reconfigure('veth99') self.wait_online('veth99:routable') # link becomes 'routable' when at least one protocol provide an valid address. Hence, we need to explicitly wait for both addresses. @@ -7586,11 +7590,11 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): check(self, True, True) check(self, True, False) - check(self, False, True) + check(self, False, True, needs_reconfigure=True) check(self, False, False) def test_dhcp_client_use_captive_portal(self): - def check(self, ipv4, ipv6): + def check(self, ipv4, ipv6, needs_reconfigure=False): os.makedirs(os.path.join(network_unit_dir, '25-dhcp-client.network.d'), exist_ok=True) with open(os.path.join(network_unit_dir, '25-dhcp-client.network.d/override.conf'), mode='w', encoding='utf-8') as f: f.write('[DHCPv4]\nUseCaptivePortal=') @@ -7600,6 +7604,8 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): f.write('\n[IPv6AcceptRA]\nUseCaptivePortal=no') networkctl_reload() + if needs_reconfigure: + networkctl_reconfigure('veth99') self.wait_online('veth99:routable') # link becomes 'routable' when at least one protocol provide an valid address. Hence, we need to explicitly wait for both addresses. @@ -7624,7 +7630,7 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities): check(self, True, True) check(self, True, False) - check(self, False, True) + check(self, False, True, needs_reconfigure=True) check(self, False, False) def test_dhcp_client_reject_captive_portal(self):