]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: extend test case for static routes
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 27 Feb 2025 18:24:39 +0000 (03:24 +0900)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Fri, 28 Feb 2025 07:51:14 +0000 (08:51 +0100)
- split out verifications into two functions,
- also check the following scenarios:
  * unmanaging an existing interface,
  * re-managing an unmanaged interface,
  * adding a new unmanaged interface,
  * removing an unmanaged interface.

test/test-network/systemd-networkd-tests.py

index dc8bc395e4b0aa54a74314488602847d4a83e45f..9f5a3ce62b2f04df69fd1327d965b079326b6338 100755 (executable)
@@ -4091,17 +4091,11 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         self.assertIn('lookup 7 ', output)
         self.assertIn('uidrange 100-200 ', output)
 
-    def _test_route_static(self, manage_foreign_routes):
-        if not manage_foreign_routes:
-            copy_networkd_conf_dropin('networkd-manage-foreign-routes-no.conf')
-
-        copy_network_unit('25-route-static.network', '12-dummy.netdev',
-                          '25-route-static-test1.network', '11-dummy.netdev')
-        start_networkd()
-        self.wait_online('dummy98:routable')
-
+    def _check_route_static(self, test1_is_managed: bool):
         output = networkctl_status('dummy98')
         print(output)
+        output = networkctl_status('test1')
+        print(output)
 
         print('### ip -6 route show dev dummy98')
         output = check_output('ip -6 route show dev dummy98')
@@ -4198,18 +4192,15 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         print(output)
         # old ip command does not show 'nexthop' keyword and weight...
         self.assertIn('2001:1234:5:bfff:ff:ff:ff:ff', output)
-        self.assertIn('via 2001:1234:5:6fff:ff:ff:ff:ff dev test1', output)
-        self.assertIn('via 2001:1234:5:7fff:ff:ff:ff:ff dev test1', output)
+        if test1_is_managed:
+            self.assertIn('via 2001:1234:5:6fff:ff:ff:ff:ff dev test1', output)
+            self.assertIn('via 2001:1234:5:7fff:ff:ff:ff:ff dev test1', output)
         self.assertIn('via 2001:1234:5:8fff:ff:ff:ff:ff dev dummy98', output)
         self.assertIn('via 2001:1234:5:9fff:ff:ff:ff:ff dev dummy98', output)
 
         check_json(networkctl_json())
 
-        copy_network_unit('25-address-static.network', copy_dropins=False)
-        networkctl_reload()
-        self.wait_online('dummy98:routable')
-
-        # check all routes managed by Manager are removed
+    def _check_unreachable_routes_removed(self):
         print('### ip -4 route show type blackhole')
         output = check_output('ip -4 route show type blackhole')
         print(output)
@@ -4240,74 +4231,52 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         print(output)
         self.assertEqual(output, '')
 
-        remove_network_unit('25-address-static.network')
-        networkctl_reload()
-        self.wait_online('dummy98:routable')
+        check_json(networkctl_json())
 
-        # check all routes managed by Manager are reconfigured
-        print('### ip -4 route show type blackhole')
-        output = check_output('ip -4 route show type blackhole')
-        print(output)
-        self.assertIn('blackhole 202.54.1.2 proto static', output)
+    def _test_route_static(self, manage_foreign_routes):
+        if not manage_foreign_routes:
+            copy_networkd_conf_dropin('networkd-manage-foreign-routes-no.conf')
 
-        print('### ip -4 route show type unreachable')
-        output = check_output('ip -4 route show type unreachable')
-        print(output)
-        self.assertIn('unreachable 202.54.1.3 proto static', output)
+        copy_network_unit('25-route-static.network', '12-dummy.netdev',
+                          '25-route-static-test1.network', '11-dummy.netdev')
+        start_networkd()
+        self.wait_online('dummy98:routable', 'test1:routable')
+        self._check_route_static(test1_is_managed=True)
 
-        print('### ip -4 route show type prohibit')
-        output = check_output('ip -4 route show type prohibit')
-        print(output)
-        self.assertIn('prohibit 202.54.1.4 proto static', output)
+        # unmanaging test1
+        remove_network_unit('25-route-static-test1.network')
+        networkctl_reload()
+        self.wait_online('dummy98:routable')
+        self.wait_operstate('test1', setup_state='unmanaged')
+        self._check_route_static(test1_is_managed=False)
 
-        print('### ip -6 route show type blackhole')
-        output = check_output('ip -6 route show type blackhole')
-        print(output)
-        self.assertIn('blackhole 2001:1234:5678::2 dev lo proto static', output)
+        # managing test1 again
+        copy_network_unit('25-route-static-test1.network')
+        networkctl_reload()
+        self.wait_online('dummy98:routable', 'test1:routable')
+        self._check_route_static(test1_is_managed=True)
 
-        print('### ip -6 route show type unreachable')
-        output = check_output('ip -6 route show type unreachable')
-        print(output)
-        self.assertIn('unreachable 2001:1234:5678::3 dev lo proto static', output)
+        # adding an unmanaged interface
+        check_output('ip link add test2 type dummy')
+        self.wait_operstate('test2', operstate='off', setup_state='unmanaged')
+        self._check_route_static(test1_is_managed=True)
 
-        print('### ip -6 route show type prohibit')
-        output = check_output('ip -6 route show type prohibit')
-        print(output)
-        self.assertIn('prohibit 2001:1234:5678::4 dev lo proto static', output)
+        # reconfiguring with another config, and check all routes managed by Manager are removed
+        copy_network_unit('25-address-static.network', copy_dropins=False)
+        networkctl_reload()
+        self.wait_online('dummy98:routable')
+        self._check_unreachable_routes_removed()
 
+        # reconfiguring the original config again
+        remove_network_unit('25-address-static.network')
+        networkctl_reload()
+        self.wait_online('dummy98:routable')
+        self._check_route_static(test1_is_managed=True)
+
+        # removing interface, and check all routes managed by Manager are removed
         remove_link('dummy98')
         time.sleep(2)
-
-        # check all routes managed by Manager are removed
-        print('### ip -4 route show type blackhole')
-        output = check_output('ip -4 route show type blackhole')
-        print(output)
-        self.assertEqual(output, '')
-
-        print('### ip -4 route show type unreachable')
-        output = check_output('ip -4 route show type unreachable')
-        print(output)
-        self.assertEqual(output, '')
-
-        print('### ip -4 route show type prohibit')
-        output = check_output('ip -4 route show type prohibit')
-        print(output)
-        self.assertEqual(output, '')
-
-        print('### ip -6 route show type blackhole')
-        output = check_output('ip -6 route show type blackhole')
-        print(output)
-        self.assertEqual(output, '')
-
-        print('### ip -6 route show type unreachable')
-        output = check_output('ip -6 route show type unreachable')
-        print(output)
-        self.assertEqual(output, '')
-
-        print('### ip -6 route show type prohibit')
-        output = check_output('ip -6 route show type prohibit')
-        print(output)
-        self.assertEqual(output, '')
+        self._check_unreachable_routes_removed()
 
     def test_route_static(self):
         first = True