From e887b3006cd0f3d5d812d4547a64c5ff830f00ec Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 22 Jan 2025 03:45:11 +0900 Subject: [PATCH] networkd-test: unconditionally stop previous invocation of networkd before starting new one 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 | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/test/networkd-test.py b/test/networkd-test.py index b806bb7fb8..1fa5d566db 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -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',