From 0eacbc12409cd6a26145475f62788c24b496c3b4 Mon Sep 17 00:00:00 2001 From: Nick Rosbrook Date: Tue, 22 Oct 2024 10:00:49 -0400 Subject: [PATCH] networkd-test: add basic tests for systemd-networkd-wait-online --dns --- test/networkd-test.py | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/networkd-test.py b/test/networkd-test.py index a698627454b..e8cee103134 100755 --- a/test/networkd-test.py +++ b/test/networkd-test.py @@ -1067,6 +1067,55 @@ DNS=127.0.0.1 self.show_journal('systemd-timedated.service') self.fail(f'Timezone: {tz}, expected: Pacific/Honolulu') + def test_wait_online_dns(self): + ''' test systemd-networkd-wait-online with --dns ''' + self.start_unit('systemd-resolved') + self.write_network( + self.config, + ( + '[Match]\n' + f'Name={self.iface}\n' + '[Network]\n' + 'DHCP=ipv4\n' + 'UseDNS=yes\n' + 'DNSDefaultRoute=yes\n' + ) + ) + self.create_iface() + self.start_unit('systemd-networkd') + subprocess.check_call( + [NETWORKD_WAIT_ONLINE, '--dns', '--interface', self.iface, '--timeout=10'] + ) + + def test_wait_online_dns_expect_timeout(self): + ''' test systemd-networkd-wait-online with --dns, and expect timeout ''' + self.start_unit('systemd-resolved') + self.write_network( + self.config, + ( + '[Match]\n' + f'Name={self.iface}\n' + '[Network]\n' + 'DHCP=ipv4\n' + 'UseDNS=no\n' + 'DNSDefaultRoute=yes\n' + ) + ) + self.create_iface() + self.start_unit('systemd-networkd') + + env = os.environ.copy() + env['SYSTEMD_LOG_LEVEL'] = 'debug' + r = subprocess.run( + [NETWORKD_WAIT_ONLINE, '--dns', '--interface', self.iface, '--timeout=5'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env, + ) + subprocess.check_call(['resolvectl']) + self.assertNotEqual(r.returncode, 0) + self.assertRegex(r.stderr, rb'No.*DNS server is accessible') + class MatchClientTest(unittest.TestCase, NetworkdTestingUtilities): """Test [Match] sections in .network files.