From 7969981891d1961c9c541407dc8022ab12eb879d Mon Sep 17 00:00:00 2001
From: Rodolfo Alonso Hernandez <ralonsoh@redhat.com>
Date: Wed, 4 Sep 2024 10:13:08 +0000
Subject: [PATCH] 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
---
 whitebox_neutron_tempest_plugin/common/utils.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

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)