diff --git a/whitebox_neutron_tempest_plugin/common/utils.py b/whitebox_neutron_tempest_plugin/common/utils.py index c9d974e..6ccca07 100644 --- a/whitebox_neutron_tempest_plugin/common/utils.py +++ b/whitebox_neutron_tempest_plugin/common/utils.py @@ -273,3 +273,20 @@ def retry_on_assert_fail(max_retries, raise AssertionError(f"Assert failed after {max_retries} retries.") return inner return decor + + +def wait_for_neutron_api(neutron_client, timeout=100): + """Waits until the Neutron API replies + + :param neutron_client: a Neutron client; it could have or not admin + permissions. + :param timeout: maximum time (in seconds) to wait for the Neutron API. + """ + def _list_agents(): + try: + neutron_client.list_extensions() + return True + except exceptions.RestClientException: + return False + + common_utils.wait_until_true(_list_agents, timeout=timeout, sleep=1)