]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-network: check status of networkd after everything cleared on tear down
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 5 Dec 2024 23:42:41 +0000 (08:42 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 10 Dec 2024 02:01:53 +0000 (11:01 +0900)
Otherwise, if networkd is failed, e.g. .network files that triggered the
failure will remain, and the next test case will start with previous
.network files. So, most subsequent test will fail.

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

index 1fd1b2290f668c32e9c63a3875d6e402206e3f38..000645c916e26bbaa64493177b6bf1338c698ece 100755 (executable)
@@ -929,17 +929,25 @@ def read_networkd_log(invocation_id=None, since=None):
 def networkd_is_failed():
     return call_quiet('systemctl is-failed -q systemd-networkd.service') != 1
 
-def stop_networkd(show_logs=True):
+def stop_networkd(show_logs=True, check_failed=True):
     global show_journal
     show_logs = show_logs and show_journal
     if show_logs:
         invocation_id = networkd_invocation_id()
-    check_output('systemctl stop systemd-networkd.socket')
-    check_output('systemctl stop systemd-networkd.service')
+
+    if check_failed:
+        check_output('systemctl stop systemd-networkd.socket')
+        check_output('systemctl stop systemd-networkd.service')
+    else:
+        call('systemctl stop systemd-networkd.socket')
+        call('systemctl stop systemd-networkd.service')
+
     if show_logs:
         print(read_networkd_log(invocation_id))
+
     # Check if networkd exits cleanly.
-    assert not networkd_is_failed()
+    if check_failed:
+        assert not networkd_is_failed()
 
 def start_networkd():
     check_output('systemctl start systemd-networkd')
@@ -1024,7 +1032,7 @@ def tear_down_common():
     flush_links()
 
     # 5. stop networkd
-    stop_networkd()
+    stop_networkd(check_failed=False)
 
     # 6. remove configs
     clear_network_units()
@@ -1041,6 +1049,9 @@ def tear_down_common():
     sys.stdout.flush()
     check_output('journalctl --sync')
 
+    # 9. check the status of networkd
+    assert not networkd_is_failed()
+
 def setUpModule():
     rm_rf(networkd_ci_temp_dir)
     cp_r(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'conf'), networkd_ci_temp_dir)