1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-06 00:58:29 +03:00

test-network: check status of networkd after everything cleared on tear down

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.
This commit is contained in:
Yu Watanabe 2024-12-06 08:42:41 +09:00
parent 91ef65784e
commit 456727b5d4

@ -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)