From 22fa8f67241fb3bf57c71c5c9e59ee5f63feca11 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Jun 2024 17:24:23 +0900 Subject: [PATCH 1/4] test-network: generate debugging logs of networkd-persistent-storage.service --- test/test-network/systemd-networkd-tests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 000180dd41..b294621de9 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -526,7 +526,8 @@ def setup_system_units(): 'ExecStart=', f'ExecStart={networkctl_bin} persistent-storage yes', 'ExecStop=', - f'ExecStop={networkctl_bin} persistent-storage no' + f'ExecStop={networkctl_bin} persistent-storage no', + 'Environment=SYSTEMD_LOG_LEVEL=debug' if enable_debug else '', ] ) From 6fec5982900efb4fcd5a6f8eca68e274f557442d Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Jun 2024 17:43:43 +0900 Subject: [PATCH 2/4] test-network: flush stream buffer and journals before/after running test --- test/test-network/systemd-networkd-tests.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index b294621de9..64fb5fce13 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -923,7 +923,11 @@ def udevadm_trigger(*args, action='add'): udevadm('trigger', '--settle', f'--action={action}', *args) def setup_common(): + # 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() + sys.stdout.flush() + check_output('journalctl --sync') def tear_down_common(): # 1. stop DHCP/RA servers @@ -956,6 +960,10 @@ def tear_down_common(): flush_routing_policy_rules() flush_routes() + # 8. flush stream buffer and journals to make not any output from the test with the next one + sys.stdout.flush() + check_output('journalctl --sync') + 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) @@ -989,6 +997,10 @@ def tearDownModule(): clear_system_units() restore_active_units() + # Flush stream buffer and journals before showing the test summary. + sys.stdout.flush() + check_output('journalctl --sync') + class Utilities(): # pylint: disable=no-member From 653c38b3ebc6607bc3bfe51fa1539228eb6c899e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Jun 2024 17:49:26 +0900 Subject: [PATCH 3/4] test-network: show PID and Invocation ID of networkd Then, we can easily find relevant journal entry on failure. This is especially useful when the test is running with --no-journal. --- test/test-network/systemd-networkd-tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 64fb5fce13..a0ca54c790 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -845,6 +845,9 @@ def radvd_check_config(config_file): def networkd_invocation_id(): return check_output('systemctl show --value -p InvocationID systemd-networkd.service') +def networkd_pid(): + return check_output('systemctl show --value -p MainPID systemd-networkd.service') + def read_networkd_log(invocation_id=None, since=None): if not invocation_id: invocation_id = networkd_invocation_id() @@ -876,6 +879,9 @@ def stop_networkd(show_logs=True): def start_networkd(): check_output('systemctl start systemd-networkd') + invocation_id = networkd_invocation_id() + pid = networkd_pid() + print(f'Started systemd-networkd.service: PID={pid}, Invocation ID={invocation_id}') def restart_networkd(show_logs=True): global show_journal @@ -886,6 +892,10 @@ def restart_networkd(show_logs=True): if show_logs: print(read_networkd_log(invocation_id)) + invocation_id = networkd_invocation_id() + pid = networkd_pid() + print(f'Restarted systemd-networkd.service: PID={pid}, Invocation ID={invocation_id}') + def networkd_pid(): return int(check_output('systemctl show --value -p MainPID systemd-networkd.service')) From dadf2bd4f464eee18cdba27280a777a926678b39 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 3 Jun 2024 18:04:55 +0900 Subject: [PATCH 4/4] test-network: introduce a .network file to protect existing interfaces --- test/test-network/systemd-networkd-tests.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index a0ca54c790..c12c28f676 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -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')