]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: introduce a .network file to protect existing interfaces 33173/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 3 Jun 2024 09:04:55 +0000 (18:04 +0900)
committerLuca Boccassi <bluca@debian.org>
Mon, 3 Jun 2024 17:41:26 +0000 (18:41 +0100)
test/test-network/systemd-networkd-tests.py

index a0ca54c7906a1c690b2b20eb4ebbae4f9629fbe5..c12c28f676dc21af33078985b882bc81e796d384 100755 (executable)
@@ -580,6 +580,15 @@ def save_existing_links():
     print('### The following links will be protected:')
     print(', '.join(sorted(list(protected_links))))
 
+def unmanage_existing_links():
+    mkdir_p(network_unit_dir)
+
+    with open(os.path.join(network_unit_dir, '00-unmanaged.network'), mode='w', encoding='utf-8') as f:
+        f.write('[Match]\n')
+        for link in protected_links:
+            f.write(f'Name={link}\n')
+        f.write('\n[Link]\nUnmanaged=yes\n')
+
 def flush_links():
     links = os.listdir('/sys/class/net')
     remove_link(*links, protect=True)
@@ -933,6 +942,9 @@ def udevadm_trigger(*args, action='add'):
     udevadm('trigger', '--settle', f'--action={action}', *args)
 
 def setup_common():
+    # Protect existing links
+    unmanage_existing_links()
+
     # We usually show something in each test. So, let's break line to make the title of a test and output
     # from the test mixed. Then, flush stream buffer and journals.
     print()
@@ -1874,6 +1886,7 @@ class NetworkdNetDevTests(unittest.TestCase, Utilities):
         self.check_tuntap(True)
 
         clear_network_units()
+        unmanage_existing_links()
         restart_networkd()
         self.wait_online('testtun99:off', 'testtap99:off', setup_state='unmanaged')