Add wait method for the Neutron API

This method checks if the Neutron API replies to a generic command
("agent list").

Related-Bug: #OSPRH-2460
Change-Id: I7982bb130e4a8ef7495e6243f656cc4095d35db8
This commit is contained in:
Rodolfo Alonso Hernandez 2024-09-04 10:13:08 +00:00
parent 0219e833da
commit 7969981891

View File

@ -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)