URL: https://github.com/freeipa/freeipa/pull/4412
Author: flo-renaud
 Title: #4412: [Backport][ipa-4-7] ipatests: wait for SSSD to become online in 
backup/restore tests
Action: opened

PR body:
"""
Manual backport of PR #4383 to ipa-4-7 branch.
There was a conflict on ipatests/pytest_ipa/integration/tasks.py because the 
file contains a additional methods on the master branch, that are not needed in 
this PR.
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/4412/head:pr4412
git checkout pr4412
From 28c880a45d6e1e5b894f94a280405909c55e6b3f Mon Sep 17 00:00:00 2001
From: Florence Blanc-Renaud <f...@redhat.com>
Date: Wed, 18 Mar 2020 11:13:19 +0100
Subject: [PATCH] ipatests: wait for SSSD to become online in backup/restore
 tests

The backup/restore tests are calling 'id admin' after restore
to make sure that the user name can be resolved after a restore.
The test should wait for SSSD backend to become online before
doing any check, otherwise there is a risk that the call to
'id admin' fails.

Fixes: https://pagure.io/freeipa/issue/8228

Signed-off-by: Florence Blanc-Renaud <f...@redhat.com>
Reviewed-By: Alexander Bokovoy <aboko...@redhat.com>
Reviewed-By: Sergey Orlov <sor...@redhat.com>
---
 ipatests/pytest_ipa/integration/tasks.py      | 24 +++++++++++++++++++
 .../test_backup_and_restore.py                |  2 ++
 2 files changed, 26 insertions(+)

diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py
index 0c6c867a6e..831b48fcf7 100755
--- a/ipatests/pytest_ipa/integration/tasks.py
+++ b/ipatests/pytest_ipa/integration/tasks.py
@@ -1947,3 +1947,27 @@ def ldapmodify_dm(host, ldif_text, **kwargs):
         '-w', host.config.dirman_password
     ]
     return host.run_command(args, stdin_text=ldif_text, **kwargs)
+
+
+def wait_for_sssd_domain_status_online(host, timeout=120):
+    """Wait up to timeout (in seconds) for sssd domain status to become Online
+
+    The method is checking the Online Status of the domain as displayed by
+    the command sssctl domain-status <domain> -o and returns successfully
+    when the status is Online.
+    This call is useful for instance when 389-ds has been stopped and restarted
+    as SSSD may need a while before it reconnects and switches from Offline
+    mode to Online.
+    """
+    pattern = re.compile(r'Online status: (?P<state>.*)\n')
+    for _i in range(0, timeout, 5):
+        result = host.run_command(
+            [paths.SSSCTL, "domain-status", host.domain.name, "-o"]
+        )
+        match = pattern.search(result.stdout_text)
+        state = match.group('state')
+        if state == 'Online':
+            break
+        time.sleep(5)
+    else:
+        raise RuntimeError("SSSD still offline")
diff --git a/ipatests/test_integration/test_backup_and_restore.py b/ipatests/test_integration/test_backup_and_restore.py
index 152f1ba9a1..df2b3ef7a8 100644
--- a/ipatests/test_integration/test_backup_and_restore.py
+++ b/ipatests/test_integration/test_backup_and_restore.py
@@ -152,6 +152,8 @@ def restore_checker(host):
 
     yield
 
+    # Wait for SSSD to become online before doing any other check
+    tasks.wait_for_sssd_domain_status_online(host)
     tasks.kinit_admin(host)
 
     for (check, assert_func), expected in zip(CHECKS, results):
_______________________________________________
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

Reply via email to