]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: add a testcase that all bound interfaces removed
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Nov 2022 05:32:26 +0000 (14:32 +0900)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 1 Nov 2022 10:28:57 +0000 (10:28 +0000)
Closes #4202.

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

index dfef73f030e79675bec1e053bd251971d01d028e..3bda8b52d5d289d0dc99a4abcbf6535b23763c38 100755 (executable)
@@ -3167,53 +3167,77 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
         self.assertRegex(output, 'via 2607:5300:203:39ff:ff:ff:ff:ff')
 
     def test_bind_carrier(self):
-        check_output('ip link add dummy98 type dummy')
-        check_output('ip link set dummy98 up')
-        time.sleep(2)
-
         copy_network_unit('25-bind-carrier.network', '11-dummy.netdev')
         start_networkd()
-        self.wait_online(['test1:routable'])
 
+        # no bound interface.
+        self.wait_operstate('test1', 'off', setup_state='configuring')
         output = check_output('ip address show test1')
         print(output)
-        self.assertRegex(output, 'UP,LOWER_UP')
-        self.assertRegex(output, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
-        self.wait_operstate('test1', 'routable')
+        self.assertNotIn('UP,LOWER_UP', output)
+        self.assertIn('DOWN', output)
+        self.assertNotIn('192.168.10', output)
 
+        # add one bound interface. The interface will be up.
+        check_output('ip link add dummy98 type dummy')
+        check_output('ip link set dummy98 up')
+        self.wait_online(['test1:routable'])
+        output = check_output('ip address show test1')
+        print(output)
+        self.assertIn('UP,LOWER_UP', output)
+        self.assertIn('inet 192.168.10.30/24 brd 192.168.10.255 scope global test1', output)
+
+        # add another bound interface. The interface is still up.
         check_output('ip link add dummy99 type dummy')
         check_output('ip link set dummy99 up')
-        time.sleep(2)
         output = check_output('ip address show test1')
         print(output)
-        self.assertRegex(output, 'UP,LOWER_UP')
-        self.assertRegex(output, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
-        self.wait_operstate('test1', 'routable')
+        self.assertIn('UP,LOWER_UP', output)
+        self.assertIn('inet 192.168.10.30/24 brd 192.168.10.255 scope global test1', output)
 
+        # remove one of the bound interfaces. The interface is still up
         remove_link('dummy98')
-        time.sleep(2)
         output = check_output('ip address show test1')
         print(output)
-        self.assertRegex(output, 'UP,LOWER_UP')
-        self.assertRegex(output, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
-        self.wait_operstate('test1', 'routable')
+        self.assertIn('UP,LOWER_UP', output)
+        self.assertIn('inet 192.168.10.30/24 brd 192.168.10.255 scope global test1', output)
 
+        # bring down the remaining bound interface. The interface will be down.
         check_output('ip link set dummy99 down')
-        time.sleep(2)
+        self.wait_operstate('test1', 'off')
+        self.wait_address_dropped('test1', r'192.168.10', ipv='-4', timeout_sec=10)
         output = check_output('ip address show test1')
         print(output)
-        self.assertNotRegex(output, 'UP,LOWER_UP')
-        self.assertRegex(output, 'DOWN')
-        self.assertNotRegex(output, '192.168.10')
-        self.wait_operstate('test1', 'off')
+        self.assertNotIn('UP,LOWER_UP', output)
+        self.assertIn('DOWN', output)
+        self.assertNotIn('192.168.10', output)
 
+        # bring up the bound interface. The interface will be up.
         check_output('ip link set dummy99 up')
-        time.sleep(2)
+        self.wait_online(['test1:routable'])
         output = check_output('ip address show test1')
         print(output)
-        self.assertRegex(output, 'UP,LOWER_UP')
-        self.assertRegex(output, 'inet 192.168.10.30/24 brd 192.168.10.255 scope global test1')
-        self.wait_operstate('test1', 'routable')
+        self.assertIn('UP,LOWER_UP', output)
+        self.assertIn('inet 192.168.10.30/24 brd 192.168.10.255 scope global test1', output)
+
+        # remove the remaining bound interface. The interface will be down.
+        remove_link('dummy99')
+        self.wait_operstate('test1', 'off')
+        self.wait_address_dropped('test1', r'192.168.10', ipv='-4', timeout_sec=10)
+        output = check_output('ip address show test1')
+        print(output)
+        self.assertNotIn('UP,LOWER_UP', output)
+        self.assertIn('DOWN', output)
+        self.assertNotIn('192.168.10', output)
+
+        # re-add one bound interface. The interface will be up.
+        check_output('ip link add dummy98 type dummy')
+        check_output('ip link set dummy98 up')
+        self.wait_online(['test1:routable'])
+        output = check_output('ip address show test1')
+        print(output)
+        self.assertIn('UP,LOWER_UP', output)
+        self.assertIn('inet 192.168.10.30/24 brd 192.168.10.255 scope global test1', output)
 
     def _test_activation_policy(self, interface, test):
         conffile = '25-activation-policy.network'