From c49db6848b41a33e107d9b746bbd2522f80e6564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20V=C3=A1vra?= Date: Mon, 26 Aug 2024 08:38:29 +0200 Subject: [PATCH 1/2] tests: Update code handling systemd-resolved for F42. Systemd-resolved changed configuration file location we need to handle both file locations. We need to set AD as nameserver for client to join realm. --- .../multihost/sssd/testlib/common/utils.py | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/tests/multihost/sssd/testlib/common/utils.py b/src/tests/multihost/sssd/testlib/common/utils.py index 8f6554a46f9..2b2cbc1ff3d 100644 --- a/src/tests/multihost/sssd/testlib/common/utils.py +++ b/src/tests/multihost/sssd/testlib/common/utils.py @@ -210,27 +210,40 @@ def service_ctrl(self, action, target_service): target_service), 1) def update_resolv_conf(self, ip_addr): - """ Update /etc/resolv.conf with Windows AD IP address + """ Set nameserver to specific ip address (Like AD server) - :param str ip_addr: IP Address to be added in resolv.conf + :param str ip_addr: IP Address to be set :return: None """ - self.multihost.log.info("Add ip addr %s in resolv.conf" % ip_addr) - nameserver = 'nameserver %s\n' % ip_addr - resolv_conf = self.multihost.get_file_contents('/etc/resolv.conf') - if isinstance(resolv_conf, bytes): - contents = resolv_conf.decode('utf-8') + self.multihost.log.info(f"Set dns to ip addr: {ip_addr}") + cmd = self.multihost.run_command(f'readlink /etc/resolv.conf', raiseonerr=False) + if 'stub-resolv.conf' in cmd.stdout_text: + # Try to change dns settings on a machine with systemd-resolved + self.set_dns_systemd_resolved(ip_addr) else: - contents = resolv_conf - contents = nameserver + contents.replace(nameserver, '') - # Chattr will not work on symlink (like from systemd resolved) - # so we ignore result - self.multihost.run_command("chattr -i /etc/resolv.conf", raiseonerr=False) - self.multihost.put_file_contents('/etc/resolv.conf', contents) - self.multihost.run_command("chattr +i /etc/resolv.conf", raiseonerr=False) - # Try to change dns settings on a machine with systemd.resolved - change_stub = f"sed -ie 's/#\?DNS=.*/DNS={ip_addr}/' /etc/systemd/resolved.conf" - self.multihost.run_command(change_stub, raiseonerr=False) + nameserver = 'nameserver %s\n' % ip_addr + resolv_conf = self.multihost.get_file_contents('/etc/resolv.conf') + if isinstance(resolv_conf, bytes): + contents = resolv_conf.decode('utf-8') + else: + contents = resolv_conf + contents = nameserver + contents.replace(nameserver, '') + # Chattr will not work on symlink (like from systemd resolved) + # so we ignore result + self.multihost.run_command("chattr -i /etc/resolv.conf", raiseonerr=False) + self.multihost.put_file_contents('/etc/resolv.conf', contents) + self.multihost.run_command("chattr +i /etc/resolv.conf", raiseonerr=False) + + def set_dns_systemd_resolved(self, ip_addr): + """ Configure systemd-resolved with an IP address + + :param str ip_addr: IP Address to be used + :return: None + """ + self.multihost.log.info(f"Configuring systemd-resolved to use: {ip_addr}") + change_dns = rf"sed -ie 's/#\?DNS=.*/DNS={ip_addr}/'" + for x in ['/etc/systemd/resolved.conf', '/usr/lib/systemd/resolved.conf']: + self.multihost.run_command(f'{change_dns} {x}', raiseonerr=False) self.multihost.run_command( "systemctl restart systemd-resolved", raiseonerr=False ) From 0a9a5985b7ca85b881862b71daf9ce86d74d6b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20V=C3=A1vra?= Date: Mon, 26 Aug 2024 14:28:53 +0200 Subject: [PATCH 2/2] tests: Addd sssd.log when sssd does not start. The sssd.log might come useful when debugging why sssd did not start. --- src/tests/multihost/sssd/testlib/common/qe_class.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/multihost/sssd/testlib/common/qe_class.py b/src/tests/multihost/sssd/testlib/common/qe_class.py index ed120fa21dc..d53e7c8676c 100644 --- a/src/tests/multihost/sssd/testlib/common/qe_class.py +++ b/src/tests/multihost/sssd/testlib/common/qe_class.py @@ -148,6 +148,7 @@ def service_sssd(self, action): time.sleep(10) return cmd.returncode self.run_command('journalctl -xeu sssd.service', raiseonerr=False) + self.run_command('cat /var/log/sssd/sssd.log', raiseonerr=False) raise SSSDException(f'Unable to {action} sssd', 1) def yum_install(self, package):