ipatests: fixture can produce IndexError

The fixture issue_and_expire_acme_cert returns a function
that fills the hosts array. If the function is not called in
the test (for instance because a test is skipped, as in
TestACMEPrune::test_prune_cert_search_size_limit), hosts = []
and hosts[0] raises an IndexError.

Fix the fixture to check first that hosts is not empty.

Related: https://pagure.io/freeipa/issue/9348

Signed-off-by: Florence Blanc-Renaud <flo@redhat.com>
Reviewed-By: Mohammad Rizwan Yusuf <myusuf@redhat.com>
This commit is contained in:
Florence Blanc-Renaud
2023-08-11 09:10:30 +02:00
parent 33c2740d82
commit a6f01115cf

View File

@@ -633,9 +633,13 @@ def issue_and_expire_acme_cert():
tasks.move_date(host, 'start', '-90days-60minutes')
# restart ipa services as date moved and wait to get things settle
time.sleep(10)
hosts[0].run_command(['ipactl', 'restart'])
time.sleep(10)
# if the internal fixture was not called (for instance because the test
# was skipped), hosts = [] and hosts[0] would produce an IndexError
# exception.
if hosts:
time.sleep(10)
hosts[0].run_command(['ipactl', 'restart'])
time.sleep(10)
class TestACMERenew(IntegrationTest):