From 19462788f162491e0aedaaf42528cae7104b8068 Mon Sep 17 00:00:00 2001 From: Stanislav Levin Date: Wed, 13 Nov 2019 20:35:25 +0300 Subject: [PATCH] ipatests: Properly kill gpg-agent There is a race condition exposed in 'test_gpg_asymmetric'. The teardown of 'tempdir' fixture and gpg-agent being called from the teardown of 'gpgkey' fixture could simultaneously remove the gnugpg's socket files. This results in an error like: ``` ================= ERRORS =================== _ ERROR at teardown of test_gpg_asymmetric __ ... > os.unlink(entry.name, dir_fd=topfd) E FileNotFoundError: [Errno 2] No such file or directory: 'S.gpg-agent.extra' /usr/lib64/python3.7/shutil.py:450: FileNotFoundError ``` The problem is that the agent is not terminated properly. Instead, gpgconf could be used to kill daemonized gpg-agent. Related: https://pagure.io/freeipa/issue/7989 Signed-off-by: Stanislav Levin Reviewed-By: Christian Heimes --- ipaplatform/base/paths.py | 1 + .../test_ipaserver/test_install/test_installutils.py | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ipaplatform/base/paths.py b/ipaplatform/base/paths.py index 2dc22ef08..f3a95500e 100644 --- a/ipaplatform/base/paths.py +++ b/ipaplatform/base/paths.py @@ -172,6 +172,7 @@ class BasePathNamespace: FIREFOX = "/usr/bin/firefox" GETCERT = "/usr/bin/getcert" GPG2 = "/usr/bin/gpg2" + GPG_CONF = "/usr/bin/gpgconf" GPG_CONNECT_AGENT = "/usr/bin/gpg-connect-agent" GPG_AGENT = "/usr/bin/gpg-agent" IPA_GETCERT = "/usr/bin/ipa-getcert" diff --git a/ipatests/test_ipaserver/test_install/test_installutils.py b/ipatests/test_ipaserver/test_install/test_installutils.py index 3d878a454..86e595167 100644 --- a/ipatests/test_ipaserver/test_install/test_installutils.py +++ b/ipatests/test_ipaserver/test_install/test_installutils.py @@ -50,8 +50,8 @@ def gpgkey(request, tempdir): f.write("verbose\n") f.write("allow-preset-passphrase\n") - # run agent in background - agent = subprocess.Popen( + # daemonize agent (detach from the console and run in the background) + subprocess.Popen( [paths.GPG_AGENT, '--batch', '--daemon'], env=env, stdout=devnull, stderr=devnull ) @@ -61,8 +61,11 @@ def gpgkey(request, tempdir): os.environ['GNUPGHOME'] = orig_gnupghome else: os.environ.pop('GNUPGHOME', None) - agent.kill() - agent.wait() + subprocess.run( + [paths.GPG_CONF, '--kill', 'all'], + check=True, + env=env, + ) request.addfinalizer(fin)