From 5af574326bd60c52ddcaf7f7cfe73f4e810bc04a Mon Sep 17 00:00:00 2001 From: Florence Blanc-Renaud Date: Thu, 11 Mar 2021 14:10:56 +0100 Subject: [PATCH] ipatests: fix TestInstalDNSSECFirst::test_resolvconf logic The test test_dnssec.py::TestInstallDNSSECFirst::test_resolvconf checks that /etc/resolv.conf points to the localhost and fails on fedora33 because systemd-resolved is in place (and /etc/resolv.conf contains 127.0.0.53). The test logic needs to be adapted. When systemd-resolved is used, the test can check the output of "resolvectl dns". Fixes: https://pagure.io/freeipa/issue/8695 Signed-off-by: Florence Blanc-Renaud Reviewed-By: Rob Crittenden Reviewed-By: Sergey Orlov Reviewed-By: Sergey Orlov Reviewed-By: Rob Crittenden --- ipatests/pytest_ipa/integration/resolver.py | 22 +++++++++++++++++++++ ipatests/test_integration/test_dnssec.py | 7 +++---- 2 files changed, 25 insertions(+), 4 deletions(-) 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):