From: Yu Watanabe Date: Wed, 20 Dec 2023 13:22:34 +0000 (+0900) Subject: network: also log drop-in config files X-Git-Tag: v256-rc1~1439 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b993e7e72e2c2bd1e372afd04bcb61a9cd6b59ac;p=thirdparty%2Fsystemd.git network: also log drop-in config files We have already show used drop-in config files in networkctl, but also showing that in log may be useful. Closes #30483. --- diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index dd3b448ab25..47433ef1ab0 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -1241,10 +1241,20 @@ int link_reconfigure_impl(Link *link, bool force) { return 0; if (network) { + _cleanup_free_ char *joined = strv_join(network->dropins, ", "); + if (link->state == LINK_STATE_INITIALIZED) - log_link_info(link, "Configuring with %s.", network->filename); + log_link_info(link, "Configuring with %s%s%s%s.", + network->filename, + isempty(joined) ? "" : " (dropins: ", + joined, + isempty(joined) ? "" : ")"); else - log_link_info(link, "Reconfiguring with %s.", network->filename); + log_link_info(link, "Reconfiguring with %s%s%s%s.", + network->filename, + isempty(joined) ? "" : " (dropins: ", + joined, + isempty(joined) ? "" : ")"); } else log_link_full(link, link->state == LINK_STATE_INITIALIZED ? LOG_DEBUG : LOG_INFO, "Unmanaging interface."); diff --git a/test/test-network/conf/11-test-unit-file.link b/test/test-network/conf/11-test-unit-file.link new file mode 100644 index 00000000000..429ac31e806 --- /dev/null +++ b/test/test-network/conf/11-test-unit-file.link @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: MIT-0 +# +# This config file is installed as part of systemd. +# It may be freely copied and edited (following the MIT No Attribution license). +# +# To make local modifications, one of the following methods may be used: +# 1. add a drop-in file that extends this file by creating the +# /etc/systemd/network/99-default.link.d/ directory and creating a +# new .conf file there. +# 2. copy this file into /etc/systemd/network or one of the other paths checked +# by systemd-udevd and edit it there. +# This file should not be edited in place, because it'll be overwritten on upgrades. + +[Match] +OriginalName=* + +[Link] +NamePolicy=keep kernel database onboard slot path +AlternativeNamesPolicy=database onboard slot path +MACAddressPolicy=persistent diff --git a/test/test-network/conf/11-test-unit-file.link.d/dropin.conf b/test/test-network/conf/11-test-unit-file.link.d/dropin.conf new file mode 100644 index 00000000000..dfddc0a46fd --- /dev/null +++ b/test/test-network/conf/11-test-unit-file.link.d/dropin.conf @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +[Link] diff --git a/test/test-network/conf/11-test-unit-file.netdev b/test/test-network/conf/11-test-unit-file.netdev new file mode 100644 index 00000000000..86af17ff9f1 --- /dev/null +++ b/test/test-network/conf/11-test-unit-file.netdev @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +[NetDev] +Name=test1 +Kind=dummy diff --git a/test/test-network/conf/11-test-unit-file.netdev.d/dropin.conf b/test/test-network/conf/11-test-unit-file.netdev.d/dropin.conf new file mode 100644 index 00000000000..6fde5989e4f --- /dev/null +++ b/test/test-network/conf/11-test-unit-file.netdev.d/dropin.conf @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +[NetDev] diff --git a/test/test-network/conf/11-test-unit-file.network b/test/test-network/conf/11-test-unit-file.network new file mode 100644 index 00000000000..0a4511bfb31 --- /dev/null +++ b/test/test-network/conf/11-test-unit-file.network @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +[Match] +Name=test1 + +[Network] +IPv6AcceptRA=no diff --git a/test/test-network/conf/11-test-unit-file.network.d/dropin.conf b/test/test-network/conf/11-test-unit-file.network.d/dropin.conf new file mode 100644 index 00000000000..f2f6099599b --- /dev/null +++ b/test/test-network/conf/11-test-unit-file.network.d/dropin.conf @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +[Network] diff --git a/test/test-network/systemd-networkd-tests.py b/test/test-network/systemd-networkd-tests.py index 4b692968033..adb60cd4893 100755 --- a/test/test-network/systemd-networkd-tests.py +++ b/test/test-network/systemd-networkd-tests.py @@ -1238,15 +1238,20 @@ class NetworkctlTests(unittest.TestCase, Utilities): print(output) self.assertRegex(output, 'Type: loopback') - def test_udev_link_file(self): - copy_network_unit('11-dummy.netdev', '11-dummy.network', '25-default.link') + def test_unit_file(self): + copy_network_unit('11-test-unit-file.netdev', '11-test-unit-file.network', '11-test-unit-file.link') start_networkd() self.wait_online(['test1:degraded']) output = check_output(*networkctl_cmd, '-n', '0', 'status', 'test1', env=env) print(output) - self.assertRegex(output, r'Link File: /run/systemd/network/25-default.link') - self.assertRegex(output, r'Network File: /run/systemd/network/11-dummy.network') + self.assertIn('Link File: /run/systemd/network/11-test-unit-file.link', output) + self.assertIn('/run/systemd/network/11-test-unit-file.link.d/dropin.conf', output) + self.assertIn('Network File: /run/systemd/network/11-test-unit-file.network', output) + self.assertIn('/run/systemd/network/11-test-unit-file.network.d/dropin.conf', output) + + output = read_networkd_log() + self.assertIn('test1: Configuring with /run/systemd/network/11-test-unit-file.network (dropins: /run/systemd/network/11-test-unit-file.network.d/dropin.conf).', output) # This test may be run on the system that has older udevd than 70f32a260b5ebb68c19ecadf5d69b3844896ba55 (v249). # In that case, the udev DB for the loopback network interface may already have ID_NET_LINK_FILE property. @@ -1254,8 +1259,8 @@ class NetworkctlTests(unittest.TestCase, Utilities): check_output(*udevadm_cmd, 'trigger', '--settle', '--action=add', '/sys/class/net/lo') output = check_output(*networkctl_cmd, '-n', '0', 'status', 'lo', env=env) print(output) - self.assertRegex(output, r'Link File: n/a') - self.assertRegex(output, r'Network File: n/a') + self.assertIn('Link File: n/a', output) + self.assertIn('Network File: n/a', output) def test_delete_links(self): copy_network_unit('11-dummy.netdev', '11-dummy.network',