]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd-test: unconditionally stop previous invocation of networkd before starting...
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 21 Jan 2025 18:45:11 +0000 (03:45 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 22 Jan 2025 10:29:59 +0000 (10:29 +0000)
When networkd is already running, creating some .network files and
friends and starting networkd does not take any effect. Let's always
restart networkd when we want to start a new invocation.

test/networkd-test.py

index b806bb7fb87b2e70b3d4d376853198f3786f7610..1fa5d566dbf4f9405e3647444431cdbdbaaf35d1 100755 (executable)
@@ -261,7 +261,7 @@ Address=192.168.250.33/24
 Gateway=192.168.250.1
 ''')
         subprocess.call(['systemctl', 'reset-failed', 'systemd-networkd', 'systemd-resolved'])
-        subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
+        subprocess.check_call(['systemctl', 'restart', 'systemd-networkd'])
         self.wait_online()
 
     def tearDown(self):
@@ -405,7 +405,8 @@ class ClientTestBase(NetworkdTestingUtilities):
 
     def start_unit(self, unit):
         try:
-            subprocess.check_call(['systemctl', 'start', unit])
+            # The service may be already started. Hence, restart it.
+            subprocess.check_call(['systemctl', 'restart', unit])
         except subprocess.CalledProcessError:
             self.show_journal(unit)
             raise
@@ -559,7 +560,7 @@ Domains= ~company
                          extra_opts='IPv6AcceptRA=no')
         except subprocess.CalledProcessError as e:
             # networkd often fails to start in LXC: https://github.com/systemd/systemd/issues/11848
-            if IS_CONTAINER and e.cmd == ['systemctl', 'start', 'systemd-networkd']:
+            if IS_CONTAINER and e.cmd == ['systemctl', 'restart', 'systemd-networkd']:
                 raise unittest.SkipTest('https://github.com/systemd/systemd/issues/11848')
             else:
                 raise
@@ -593,7 +594,7 @@ Domains= ~company ~.
                          extra_opts='IPv6AcceptRA=no')
         except subprocess.CalledProcessError as e:
             # networkd often fails to start in LXC: https://github.com/systemd/systemd/issues/11848
-            if IS_CONTAINER and e.cmd == ['systemctl', 'start', 'systemd-networkd']:
+            if IS_CONTAINER and e.cmd == ['systemctl', 'restart', 'systemd-networkd']:
                 raise unittest.SkipTest('https://github.com/systemd/systemd/issues/11848')
             else:
                 raise
@@ -1129,7 +1130,7 @@ Name=test_*
 [Network]
 IPv6AcceptRA=no
 ''')
-        subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
+        subprocess.check_call(['systemctl', 'restart', 'systemd-networkd'])
         self.assert_link_states(test_if1='managed', fake_if2='unmanaged')
 
     def test_inverted_matching(self):
@@ -1146,7 +1147,7 @@ Name=!nonexistent *peer*
 [Network]
 IPv6AcceptRA=no
 '''.format(mac))
-        subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
+        subprocess.check_call(['systemctl', 'restart', 'systemd-networkd'])
         self.assert_link_states(test_veth='managed', test_peer='unmanaged')
 
 
@@ -1185,7 +1186,7 @@ class UnmanagedClientTest(unittest.TestCase, NetworkdTestingUtilities):
 
     def test_unmanaged_setting(self):
         """Verify link states with Unmanaged= settings, hot-plug."""
-        subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
+        subprocess.check_call(['systemctl', 'restart', 'systemd-networkd'])
         self.create_iface()
         self.assert_link_states(m1def='managed',
                                 m1man='managed',
@@ -1195,7 +1196,7 @@ class UnmanagedClientTest(unittest.TestCase, NetworkdTestingUtilities):
     def test_unmanaged_setting_coldplug(self):
         """Verify link states with Unmanaged= settings, cold-plug."""
         self.create_iface()
-        subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
+        subprocess.check_call(['systemctl', 'restart', 'systemd-networkd'])
         self.assert_link_states(m1def='managed',
                                 m1man='managed',
                                 m1unm='unmanaged',
@@ -1205,7 +1206,7 @@ class UnmanagedClientTest(unittest.TestCase, NetworkdTestingUtilities):
         """Verify link states with a catch-all config, hot-plug."""
         # Don't actually catch ALL interfaces.  It messes up the host.
         self.write_network('50-all.network', "[Match]\nName=m[01]???\n")
-        subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
+        subprocess.check_call(['systemctl', 'restart', 'systemd-networkd'])
         self.create_iface()
         self.assert_link_states(m1def='managed',
                                 m1man='managed',
@@ -1217,7 +1218,7 @@ class UnmanagedClientTest(unittest.TestCase, NetworkdTestingUtilities):
         # Don't actually catch ALL interfaces.  It messes up the host.
         self.write_network('50-all.network', "[Match]\nName=m[01]???\n")
         self.create_iface()
-        subprocess.check_call(['systemctl', 'start', 'systemd-networkd'])
+        subprocess.check_call(['systemctl', 'restart', 'systemd-networkd'])
         self.assert_link_states(m1def='managed',
                                 m1man='managed',
                                 m1unm='unmanaged',