From c2b230ce64bb7a29572cbfabbd23dd0900c7fce3 Mon Sep 17 00:00:00 2001 From: Sergey Orlov Date: Thu, 7 Nov 2019 17:53:24 +0100 Subject: [PATCH] ipatests: replace ad hoc backup with FileBackup helper Test test_smb_mount_and_access_by_different_users was failing with message ``` kdestroy: Permission denied while initializing krb5 ``` This happened because the previous test `test_smb_access_for_ad_user_at_ipa_client` was calling the fixture `enable_smb_client_dns_lookup_kdc` which was doing backup of krb5.conf in a wrong way: - mktemp (to create a temp file) - cp /etc/krb5.conf to the temp file - ... - mv tempfile /etc/krb5.conf This flow looses the file permissions, because mktemp creates a file using the default umask, which results in -rw------- permissions. The copy does not modify the permissions, and the mv keeps the permissions from the source => /etc/krb5.conf now has -rw-------. Fixes: https://pagure.io/freeipa/issue/8115 Reviewed-By: Alexander Bokovoy --- ipatests/test_integration/test_smb.py | 52 +++++++++++++-------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/ipatests/test_integration/test_smb.py b/ipatests/test_integration/test_smb.py index 52cdbcda7..5068a0ea0 100644 --- a/ipatests/test_integration/test_smb.py +++ b/ipatests/test_integration/test_smb.py @@ -77,15 +77,13 @@ class TestSMB(IntegrationTest): @pytest.yield_fixture def enable_smb_client_dns_lookup_kdc(self): smbclient = self.smbclient - save_file = tasks.create_temp_file(smbclient) - smbclient.run_command(['cp', paths.KRB5_CONF, save_file]) - krb5_conf = smbclient.get_file_contents( - paths.KRB5_CONF, encoding='utf-8') - krb5_conf = krb5_conf.replace( - 'dns_lookup_kdc = false', 'dns_lookup_kdc = true') - smbclient.put_file_contents(paths.KRB5_CONF, krb5_conf) - yield - smbclient.run_command(['mv', save_file, paths.KRB5_CONF]) + with tasks.FileBackup(smbclient, paths.KRB5_CONF): + krb5_conf = smbclient.get_file_contents( + paths.KRB5_CONF, encoding='utf-8') + krb5_conf = krb5_conf.replace( + 'dns_lookup_kdc = false', 'dns_lookup_kdc = true') + smbclient.put_file_contents(paths.KRB5_CONF, krb5_conf) + yield @pytest.yield_fixture def samba_share_public(self): @@ -99,25 +97,23 @@ class TestSMB(IntegrationTest): # apply selinux context only if selinux is enabled if tasks.is_selinux_enabled(smbserver): smbserver.run_command(['chcon', '-t', 'samba_share_t', share_path]) - smbconf_save_file = tasks.create_temp_file(smbserver) - smbserver.run_command(['cp', paths.SMB_CONF, smbconf_save_file]) - smb_conf = smbserver.get_file_contents( - paths.SMB_CONF, encoding='utf-8') - smb_conf += textwrap.dedent(''' - [{name}] - path = {path} - writable = yes - browsable=yes - '''.format(name=share_name, path=share_path)) - smbserver.put_file_contents(paths.SMB_CONF, smb_conf) - smbserver.run_command(['systemctl', 'restart', 'smb']) - wait_smbd_functional(smbserver) - yield { - 'name': share_name, - 'server_path': share_path, - 'unc': '//{}/{}'.format(smbserver.hostname, share_name) - } - smbserver.run_command(['mv', smbconf_save_file, paths.SMB_CONF]) + with tasks.FileBackup(smbserver, paths.SMB_CONF): + smb_conf = smbserver.get_file_contents( + paths.SMB_CONF, encoding='utf-8') + smb_conf += textwrap.dedent(''' + [{name}] + path = {path} + writable = yes + browsable=yes + '''.format(name=share_name, path=share_path)) + smbserver.put_file_contents(paths.SMB_CONF, smb_conf) + smbserver.run_command(['systemctl', 'restart', 'smb']) + wait_smbd_functional(smbserver) + yield { + 'name': share_name, + 'server_path': share_path, + 'unc': '//{}/{}'.format(smbserver.hostname, share_name) + } smbserver.run_command(['systemctl', 'restart', 'smb']) wait_smbd_functional(smbserver) smbserver.run_command(['rmdir', share_path])