1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-04 09:18:12 +03:00

networkd-test: add basic tests for systemd-networkd-wait-online --dns

This commit is contained in:
Nick Rosbrook 2024-10-22 10:00:49 -04:00
parent 2405c6c278
commit 0eacbc1240

View File

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