URL: https://github.com/freeipa/freeipa/pull/5965 Author: flo-renaud Title: #5965: [Backport][ipa-4-9] ipatests: Refactor test_check_otpd_after_idle_timeout Action: opened
PR body: """ This PR was opened automatically because PR #5952 was pushed to master and backport to ipa-4-9 is required. """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/5965/head:pr5965 git checkout pr5965
From 37a4949f0d0923f803733f3536bec3d6df8b6e02 Mon Sep 17 00:00:00 2001 From: Anuja More <am...@redhat.com> Date: Thu, 5 Aug 2021 12:27:38 +0530 Subject: [PATCH] ipatests: Refactor test_check_otpd_after_idle_timeout Use whole date when calling journalctl --since ipa-otpd don't flush its logs to syslog immediately, so check with run_repeatedly. Also list failed units when ldap connection is timed out. Related: https://pagure.io/freeipa/issue/6587 Signed-off-by: Anuja More <am...@redhat.com> --- ipatests/test_integration/test_otp.py | 31 ++++++++++++++++----------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/ipatests/test_integration/test_otp.py b/ipatests/test_integration/test_otp.py index fd55898caeb..35347089796 100644 --- a/ipatests/test_integration/test_otp.py +++ b/ipatests/test_integration/test_otp.py @@ -313,6 +313,13 @@ def test_2fa_disable_single_prompt(self): @pytest.fixture def setup_otp_nsslapd(self): + check_services = self.master.run_command( + ['systemctl', 'list-units', '--state=failed'] + ) + assert "0 loaded units listed" in check_services.stdout_text + assert "ipa-otpd" not in check_services.stdout_text + # Be sure no services are running and failed units + self.master.run_command(['killall', 'ipa-otpd'], raiseonerr=False) # setting nsslapd-idletimeout new_limit = 30 conn = self.master.ldap_connect() @@ -326,13 +333,6 @@ def setup_otp_nsslapd(self): nsslapd-idletimeout: {limit} """) tasks.ldapmodify_dm(self.master, ldap_query.format(limit=new_limit)) - # Be sure no services are running and failed units - self.master.run_command(['killall', 'ipa-otpd'], raiseonerr=False) - check_services = self.master.run_command( - ['systemctl', 'list-units', '--state=failed'] - ) - assert "0 loaded units listed" in check_services.stdout_text - assert "ipa-otpd" not in check_services.stdout_text yield # cleanup tasks.ldapmodify_dm(self.master, ldap_query.format(limit=orig_limit)) @@ -346,7 +346,7 @@ def test_check_otpd_after_idle_timeout(self, setup_otp_nsslapd): Test to verify that when the nsslapd-idletimeout is exceeded (30s idle, 60s sleep) then the ipa-otpd process should exit without error. """ - since = time.strftime('%H:%M:%S') + since = time.strftime('%Y-%m-%d %H:%M:%S') tasks.kinit_admin(self.master) otpuid, totp = add_otptoken(self.master, USER, otptype="totp") try: @@ -354,14 +354,19 @@ def test_check_otpd_after_idle_timeout(self, setup_otp_nsslapd): otpvalue = totp.generate(int(time.time())).decode("ascii") kinit_otp(self.master, USER, password=PASSWORD, otp=otpvalue) time.sleep(60) + + def test_cb(cmd_jornalctl): + # check if LDAP connection is timed out + expected_msg = "Can't contact LDAP server" + return expected_msg in cmd_jornalctl + + # ipa-otpd don't flush its logs to syslog immediately + cmd = ['journalctl', '--since={}'.format(since)] + tasks.run_repeatedly( + self.master, command=cmd, test=test_cb, timeout=90) failed_services = self.master.run_command( ['systemctl', 'list-units', '--state=failed'] ) assert "ipa-otpd" not in failed_services.stdout_text - cmd_jornalctl = self.master.run_command( - ['journalctl', '--since={}'.format(since)] - ) - regex = r".*ipa-otpd@.*\sSucceeded" - assert re.search(regex, cmd_jornalctl.stdout_text) finally: del_otptoken(self.master, otpuid)
_______________________________________________ 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