7e1b55
From eac03d6828d0bac1925c897090fc77e250eaee04 Mon Sep 17 00:00:00 2001
7e1b55
From: Anuja More <amore@redhat.com>
7e1b55
Date: Thu, 5 Aug 2021 12:27:38 +0530
7e1b55
Subject: [PATCH] ipatests: Refactor test_check_otpd_after_idle_timeout
7e1b55
7e1b55
Use whole date when calling journalctl --since
7e1b55
ipa-otpd don't flush its logs to syslog immediately,
7e1b55
so check with run_repeatedly.
7e1b55
Also list failed units when ldap connection is
7e1b55
timed out.
7e1b55
7e1b55
Related: https://pagure.io/freeipa/issue/6587
7e1b55
7e1b55
Signed-off-by: Anuja More <amore@redhat.com>
7e1b55
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
7e1b55
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
7e1b55
---
7e1b55
 ipatests/test_integration/test_otp.py | 31 ++++++++++++++++-----------
7e1b55
 1 file changed, 18 insertions(+), 13 deletions(-)
7e1b55
7e1b55
diff --git a/ipatests/test_integration/test_otp.py b/ipatests/test_integration/test_otp.py
7e1b55
index fd55898ca..353470897 100644
7e1b55
--- a/ipatests/test_integration/test_otp.py
7e1b55
+++ b/ipatests/test_integration/test_otp.py
7e1b55
@@ -313,6 +313,13 @@ class TestOTPToken(IntegrationTest):
7e1b55
 
7e1b55
     @pytest.fixture
7e1b55
     def setup_otp_nsslapd(self):
7e1b55
+        check_services = self.master.run_command(
7e1b55
+            ['systemctl', 'list-units', '--state=failed']
7e1b55
+        )
7e1b55
+        assert "0 loaded units listed" in check_services.stdout_text
7e1b55
+        assert "ipa-otpd" not in check_services.stdout_text
7e1b55
+        # Be sure no services are running and failed units
7e1b55
+        self.master.run_command(['killall', 'ipa-otpd'], raiseonerr=False)
7e1b55
         # setting nsslapd-idletimeout
7e1b55
         new_limit = 30
7e1b55
         conn = self.master.ldap_connect()
7e1b55
@@ -326,13 +333,6 @@ class TestOTPToken(IntegrationTest):
7e1b55
             nsslapd-idletimeout: {limit}
7e1b55
         """)
7e1b55
         tasks.ldapmodify_dm(self.master, ldap_query.format(limit=new_limit))
7e1b55
-        # Be sure no services are running and failed units
7e1b55
-        self.master.run_command(['killall', 'ipa-otpd'], raiseonerr=False)
7e1b55
-        check_services = self.master.run_command(
7e1b55
-            ['systemctl', 'list-units', '--state=failed']
7e1b55
-        )
7e1b55
-        assert "0 loaded units listed" in check_services.stdout_text
7e1b55
-        assert "ipa-otpd" not in check_services.stdout_text
7e1b55
         yield
7e1b55
         # cleanup
7e1b55
         tasks.ldapmodify_dm(self.master, ldap_query.format(limit=orig_limit))
7e1b55
@@ -346,7 +346,7 @@ class TestOTPToken(IntegrationTest):
7e1b55
         Test to verify that when the nsslapd-idletimeout is exceeded (30s idle,
7e1b55
         60s sleep) then the ipa-otpd process should exit without error.
7e1b55
         """
7e1b55
-        since = time.strftime('%H:%M:%S')
7e1b55
+        since = time.strftime('%Y-%m-%d %H:%M:%S')
7e1b55
         tasks.kinit_admin(self.master)
7e1b55
         otpuid, totp = add_otptoken(self.master, USER, otptype="totp")
7e1b55
         try:
7e1b55
@@ -354,14 +354,19 @@ class TestOTPToken(IntegrationTest):
7e1b55
             otpvalue = totp.generate(int(time.time())).decode("ascii")
7e1b55
             kinit_otp(self.master, USER, password=PASSWORD, otp=otpvalue)
7e1b55
             time.sleep(60)
7e1b55
+
7e1b55
+            def test_cb(cmd_jornalctl):
7e1b55
+                # check if LDAP connection is timed out
7e1b55
+                expected_msg = "Can't contact LDAP server"
7e1b55
+                return expected_msg in cmd_jornalctl
7e1b55
+
7e1b55
+            # ipa-otpd don't flush its logs to syslog immediately
7e1b55
+            cmd = ['journalctl', '--since={}'.format(since)]
7e1b55
+            tasks.run_repeatedly(
7e1b55
+                self.master, command=cmd, test=test_cb, timeout=90)
7e1b55
             failed_services = self.master.run_command(
7e1b55
                 ['systemctl', 'list-units', '--state=failed']
7e1b55
             )
7e1b55
             assert "ipa-otpd" not in failed_services.stdout_text
7e1b55
-            cmd_jornalctl = self.master.run_command(
7e1b55
-                ['journalctl', '--since={}'.format(since)]
7e1b55
-            )
7e1b55
-            regex = r".*ipa-otpd@.*\sSucceeded"
7e1b55
-            assert re.search(regex, cmd_jornalctl.stdout_text)
7e1b55
         finally:
7e1b55
             del_otptoken(self.master, otpuid)
7e1b55
-- 
7e1b55
2.31.1
7e1b55