]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: merge two IPv4LL tests
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 8 Jul 2022 23:58:48 +0000 (08:58 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 9 Jul 2022 02:44:25 +0000 (11:44 +0900)
test/test-network/systemd-networkd-tests.py

index 37e3dedd5ad8dda05455d384c4797ed877d8b010..9801441f96ff0ff635fef91affa7aa06a3955da1 100755 (executable)
@@ -4922,65 +4922,41 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
         print(output)
         self.assertRegex(output, 'onlink')
 
-    def test_dhcp_client_with_ipv4ll_with_dhcp_server(self):
+    def test_dhcp_client_with_ipv4ll(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', '25-dhcp-server-veth-peer.network',
                                         '25-dhcp-client-with-ipv4ll.network')
         start_networkd()
-        self.wait_online(['veth-peer:carrier'])
-        start_dnsmasq(lease_time='2m')
-        self.wait_online(['veth99:routable', 'veth-peer:routable'])
+        # we need to increase timeout above default, as this will need to wait for
+        # systemd-networkd to get the dhcpv4 transient failure event
+        self.wait_online(['veth99:degraded', 'veth-peer:routable'], timeout='60s')
 
-        output = check_output('ip address show dev veth99')
+        output = check_output('ip -4 address show dev veth99')
         print(output)
+        self.assertNotIn('192.168.5.', output)
+        self.assertRegex(output, r'inet 169\.254\.\d+\.\d+/16 metric 2048 brd 169\.254\.255\.255 scope link')
 
-        output = check_output('ip -6 address show dev veth99 scope global dynamic')
-        self.assertNotRegex(output, r'inet6 2600::[0-9a-f]+/128 scope global dynamic')
-        output = check_output('ip -6 address show dev veth99 scope link')
-        self.assertRegex(output, r'inet6 .* scope link')
-        output = check_output('ip -4 address show dev veth99 scope global dynamic')
-        self.assertRegex(output, r'inet 192\.168\.5\.\d+/24 metric 1024 brd 192\.168\.5\.255 scope global dynamic veth99')
-        output = check_output('ip -4 address show dev veth99 scope link')
-        self.assertNotRegex(output, r'inet 169\.254\.\d+\.\d+/16 metric 2048 brd 169\.254\.255\.255 scope link')
-
-        print('Wait for the DHCP lease to be expired')
-        time.sleep(120)
+        start_dnsmasq(lease_time='2m')
+        print('Wait for a DHCP lease to be acquired and the IPv4LL address to be dropped')
+        self.wait_address('veth99', r'inet 192\.168\.5\.\d+/24 metric 1024 brd 192\.168\.5\.255 scope global dynamic', ipv='-4')
+        self.wait_address_dropped('veth99', r'inet 169\.254\.\d+\.\d+/16 metric 2048 brd 169\.254\.255\.255 scope link', scope='link', ipv='-4')
+        self.wait_online(['veth99:routable'])
 
-        output = check_output('ip address show dev veth99')
+        output = check_output('ip -4 address show dev veth99')
         print(output)
-
-        output = check_output('ip -6 address show dev veth99 scope global dynamic')
-        self.assertNotRegex(output, r'inet6 2600::[0-9a-f]+/128 scope global dynamic')
-        output = check_output('ip -6 address show dev veth99 scope link')
-        self.assertRegex(output, r'inet6 .* scope link')
-        output = check_output('ip -4 address show dev veth99 scope global dynamic')
         self.assertRegex(output, r'inet 192\.168\.5\.\d+/24 metric 1024 brd 192\.168\.5\.255 scope global dynamic veth99')
-        output = check_output('ip -4 address show dev veth99 scope link')
-        self.assertNotRegex(output, r'inet 169\.254\.\d+\.\d+/16 metric 2048 brd 169\.254\.255\.255 scope link')
+        self.assertNotIn('169.254.', output)
+        self.assertNotIn('scope link', output)
 
-    def test_dhcp_client_with_ipv4ll_without_dhcp_server(self):
-        copy_unit_to_networkd_unit_path('25-veth.netdev', '25-dhcp-server-veth-peer.network',
-                                        '25-dhcp-client-with-ipv4ll.network')
-        start_networkd()
-        # we need to increase timeout above default, as this will need to wait for
-        # systemd-networkd to get the dhcpv4 transient failure event
-        self.wait_online(['veth99:degraded', 'veth-peer:routable'], timeout='60s')
+        stop_dnsmasq()
+        print('Wait for the DHCP lease to be expired and an IPv4LL address to be acquired')
+        self.wait_address_dropped('veth99', r'inet 192\.168\.5\.\d+/24 metric 1024 brd 192\.168\.5\.255 scope global dynamic', ipv='-4', timeout_sec=120)
+        self.wait_address('veth99', r'inet 169\.254\.\d+\.\d+/16 metric 2048 brd 169\.254\.255\.255 scope link', scope='link', ipv='-4')
 
-        output = check_output('ip address show dev veth99')
+        output = check_output('ip -4 address show dev veth99')
         print(output)
-
-        output = check_output('ip -6 address show dev veth99 scope global dynamic')
-        self.assertNotRegex(output, r'inet6 2600::[0-9a-f]+/128 scope global dynamic')
-        output = check_output('ip -6 address show dev veth99 scope link')
-        self.assertRegex(output, r'inet6 .* scope link')
-        output = check_output('ip -4 address show dev veth99 scope global dynamic')
-        self.assertNotRegex(output, r'inet 192\.168\.5\.\d+/24 metric 1024 brd 192\.168\.5\.255 scope global dynamic veth99')
-        output = check_output('ip -4 address show dev veth99 scope link')
+        self.assertNotIn('192.168.5.', output)
         self.assertRegex(output, r'inet 169\.254\.\d+\.\d+/16 metric 2048 brd 169\.254\.255\.255 scope link')
 
-        start_dnsmasq(lease_time='2m')
-        self.wait_address('veth99', r'inet 192\.168\.5\.\d+/24 metric 1024 brd 192\.168\.5\.255 scope global dynamic', ipv='-4')
-        self.wait_address_dropped('veth99', r'inet 169\.254\.\d+\.\d+/16 metric 2048 brd 169\.255\.255\.255 scope link', scope='link', ipv='-4')
-
     def test_dhcp_client_use_dns_yes(self):
         copy_unit_to_networkd_unit_path('25-veth.netdev', '25-dhcp-server-veth-peer.network', '25-dhcp-client-use-dns-yes.network')