From ef752bf208d2fb2fb1b559acd88a81bf535b1967 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Cami?= Date: Thu, 4 Mar 2021 07:10:13 +0100 Subject: [PATCH] ipatests: tasks.py: add wait_for_ipa_to_start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wait_for_ipa_to_start(host) waits for ipactl to return RUNNING for all IPA services on the specified host. Related: https://pagure.io/freeipa/issue/8534 Signed-off-by: François Cami Reviewed-By: Florence Blanc-Renaud Reviewed-By: Rob Crittenden Reviewed-By: Mohammad Rizwan Yusuf --- ipatests/pytest_ipa/integration/tasks.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py index 8c4dd9553..3102e47a3 100755 --- a/ipatests/pytest_ipa/integration/tasks.py +++ b/ipatests/pytest_ipa/integration/tasks.py @@ -47,6 +47,7 @@ from cryptography import x509 from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.backends import default_backend +from datetime import datetime, timedelta from ipapython import certdb from ipapython import ipautil @@ -2587,6 +2588,26 @@ def get_healthcheck_version(host): return healthcheck_version +def wait_for_ipa_to_start(host, timeout=60): + """Wait up to timeout seconds for ipa to start on a given host. + + If DS is restarted, and SSSD must be online, please consider using + wait_for_sssd_domain_status_online(host) in the test after calling + this method. + """ + interval = 1 + end_time = datetime.now() + timedelta(seconds=timeout) + for _i in range(0, timeout, interval): + if datetime.now() > end_time: + raise RuntimeError("Request timed out") + time.sleep(interval) + result = host.run_command( + [paths.IPACTL, "status"], raiseonerr=False + ) + if result.returncode == 0: + break + + def run_ssh_cmd( from_host=None, to_host=None, username=None, cmd=None, auth_method=None, password=None, private_key_path=None,