URL: https://github.com/freeipa/freeipa/pull/6054 Author: stanislavlevin Title: #6054: ipatests: TestMultipleExternalCA: Create tempfiles on remote host Action: opened
PR body: """ Previously, `test_master_install_ca1` and `test_master_install_ca2` attempt to create tempdirs on local host and later write some content into the returned paths on remote host. This fails if a remote host is a local one. The existent `create_temp_file` function has been extended to support `suffix` option of `mktemp`. Fixes: https://pagure.io/freeipa/issue/9013 Signed-off-by: Stanislav Levin <s...@altlinux.org> """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/6054/head:pr6054 git checkout pr6054
From 8be2c9e831dbdcc62f4a2e6d9c5d9d4574fd885a Mon Sep 17 00:00:00 2001 From: Stanislav Levin <s...@altlinux.org> Date: Tue, 19 Oct 2021 17:19:03 +0300 Subject: [PATCH] ipatests: TestMultipleExternalCA: Create tempfiles on remote host Previously, `test_master_install_ca1` and `test_master_install_ca2` attempt to create tempdirs on local host and later write some content into the returned paths on remote host. This fails if a remote host is a local one. The existent `create_temp_file` function has been extended to support `suffix` option of `mktemp`. Fixes: https://pagure.io/freeipa/issue/9013 Signed-off-by: Stanislav Levin <s...@altlinux.org> --- ipatests/pytest_ipa/integration/tasks.py | 6 ++++-- ipatests/test_integration/test_external_ca.py | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py index a34f6edf17b..f5eb3f5718c 100755 --- a/ipatests/pytest_ipa/integration/tasks.py +++ b/ipatests/pytest_ipa/integration/tasks.py @@ -2099,13 +2099,15 @@ def ldapsearch_dm(host, base, ldap_args, scope='sub', **kwargs): return host.run_command(args, **kwargs) -def create_temp_file(host, directory=None, create_file=True): - """Creates temporary file using mktemp.""" +def create_temp_file(host, *, directory=None, suffix=None, create_file=True): + """Creates temporary file using mktemp. See `man 1 mktemp`.""" cmd = ['mktemp'] if create_file is False: cmd += ['--dry-run'] if directory is not None: cmd += ['-p', directory] + if suffix is not None: + cmd.extend(["--suffix", suffix]) return host.run_command(cmd).stdout_text.strip() diff --git a/ipatests/test_integration/test_external_ca.py b/ipatests/test_integration/test_external_ca.py index d48d73deb15..bdb7fb65e9a 100644 --- a/ipatests/test_integration/test_external_ca.py +++ b/ipatests/test_integration/test_external_ca.py @@ -20,7 +20,6 @@ import os import re import time -import tempfile from cryptography import x509 from cryptography.hazmat.backends import default_backend @@ -464,8 +463,12 @@ class TestMultipleExternalCA(IntegrationTest): def test_master_install_ca1(self): install_server_external_ca_step1(self.master) # Sign CA, transport it to the host and get ipa a root ca paths. - root_ca_fname1 = tempfile.mkdtemp(suffix='root_ca.crt', dir=paths.TMP) - ipa_ca_fname1 = tempfile.mkdtemp(suffix='ipa_ca.crt', dir=paths.TMP) + root_ca_fname1 = tasks.create_temp_file( + self.master, directory=paths.TMP, suffix="root_ca.crt" + ) + ipa_ca_fname1 = tasks.create_temp_file( + self.master, directory=paths.TMP, suffix="ipa_ca.crt" + ) ipa_csr = self.master.get_file_contents(paths.ROOT_IPA_CSR) @@ -485,8 +488,12 @@ def test_master_install_ca1(self): assert "CN=RootCA1" in result.stdout_text def test_master_install_ca2(self): - root_ca_fname2 = tempfile.mkdtemp(suffix='root_ca.crt', dir=paths.TMP) - ipa_ca_fname2 = tempfile.mkdtemp(suffix='ipa_ca.crt', dir=paths.TMP) + root_ca_fname2 = tasks.create_temp_file( + self.master, directory=paths.TMP, suffix="root_ca.crt" + ) + ipa_ca_fname2 = tasks.create_temp_file( + self.master, directory=paths.TMP, suffix="ipa_ca.crt" + ) self.master.run_command([ paths.IPA_CACERT_MANAGE, 'renew', '--external-ca'])
_______________________________________________ FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org Do not reply to spam on the list, report it: https://pagure.io/fedora-infrastructure