diff --git a/ipatests/pytest_ipa/integration/resolver.py b/ipatests/pytest_ipa/integration/resolver.py index 43b2e2b48..5bfbbf4fe 100644 --- a/ipatests/pytest_ipa/integration/resolver.py +++ b/ipatests/pytest_ipa/integration/resolver.py @@ -1,6 +1,7 @@ import os import abc import logging +import re import textwrap import time @@ -131,6 +132,16 @@ class Resolver(abc.ABC): :param state: internal state object specific to subclass implementaion """ + def uses_localhost_as_dns(self): + """Return true if the localhost is set as DNS server. + + Default implementation checks the content of /etc/resolv.conf + """ + resolvconf = self.host.get_file_contents(paths.RESOLV_CONF, 'utf-8') + patterns = [r"^\s*nameserver\s+127\.0\.0\.1\s*$", + r"^\s*nameserver\s+::1\s*$"] + return any(re.search(p, resolvconf, re.MULTILINE) for p in patterns) + class ResolvedResolver(Resolver): RESOLVED_RESOLV_CONF = { @@ -192,6 +203,17 @@ class ResolvedResolver(Resolver): self.RESOLVED_CONF_FILE, state['resolved_config']) self._restart_resolved() + def uses_localhost_as_dns(self): + """Return true if the localhost is set as DNS server. + + When systemd-resolved is in use, the DNS can be found using + the command resolvectldns. + """ + dnsconf = self.host.run_command(['resolvectl', 'dns']).stdout_text + patterns = [r"^Global:.*\s+127.0.0.1\s+.*$", + r"^Global:.*\s+::1\s+.*$"] + return any(re.search(p, dnsconf, re.MULTILINE) for p in patterns) + class PlainFileResolver(Resolver): IPATESTS_RESOLVER_COMMENT = '# created by ipatests' diff --git a/ipatests/test_integration/test_dnssec.py b/ipatests/test_integration/test_dnssec.py index d80a77a81..bae16120a 100644 --- a/ipatests/test_integration/test_dnssec.py +++ b/ipatests/test_integration/test_dnssec.py @@ -462,11 +462,10 @@ class TestInstallDNSSECFirst(IntegrationTest): self.master.run_command(args) self.replicas[0].run_command(args) - def test_resolvconf(self): - # check that resolv.conf contains IP address for localhost + def test_servers_use_localhost_as_dns(self): + # check that localhost is set as DNS server for host in [self.master, self.replicas[0]]: - resolvconf = host.get_file_contents(paths.RESOLV_CONF, 'utf-8') - assert any(ip in resolvconf for ip in ('127.0.0.1', '::1')) + assert host.resolver.uses_localhost_as_dns() class TestMigrateDNSSECMaster(IntegrationTest):