Add LB connectivity tests in mt hybrid scenario
Related-Prod: PRODX-51689
Change-Id: I43d4aee780a3c3d387a5a4ed24e4b7b58c34c22d
(cherry picked from commit b895d24f27f38e5495625b9109a38358e0dc73e1)
diff --git a/ironic_tempest_plugin/common/waiters.py b/ironic_tempest_plugin/common/waiters.py
index 673e646..d80ba18 100644
--- a/ironic_tempest_plugin/common/waiters.py
+++ b/ironic_tempest_plugin/common/waiters.py
@@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import time
+
from oslo_log import log
from tempest import config
from tempest.lib.common.utils import test_utils
@@ -194,3 +196,64 @@
% {'node_id': node_id, 'timeout': timeout,
'field': field, 'value': value})
raise lib_exc.TimeoutException(msg)
+
+
+def wait_for_deleted_status_or_not_found(
+ show_client, id, status_key, check_interval, check_timeout,
+ root_tag=None, **kwargs):
+ """Waits for an object to reach a DELETED status or be not found (404).
+
+ :param show_client: The tempest service client show method.
+ Ex. cls.os_primary.servers_client.show_server
+ :param id: The id of the object to query.
+ :param status_key: The key of the status field in the response.
+ Ex. provisioning_status
+ :param check_interval: How often to check the status, in seconds.
+ :param check_timeout: The maximum time, in seconds, to check the status.
+ :param root_tag: The root tag on the response to remove, if any.
+ :raises CommandFailed: Raised if the object goes into ERROR and ERROR was
+ not the desired status.
+ :raises TimeoutException: The object did not achieve the status or ERROR in
+ the check_timeout period.
+ :returns: None
+ """
+ start = int(time.time())
+ LOG.info(
+ "Waiting for %s status to update to DELETED or be not found (404)",
+ show_client.__name__,
+ )
+ while True:
+ try:
+ response = show_client(id, **kwargs)
+ except lib_exc.NotFound:
+ LOG.info("Object with ID %s is not found.", id)
+ return
+
+ if root_tag:
+ object_details = response[root_tag]
+ else:
+ object_details = response
+
+ if object_details[status_key] == 'DELETED':
+ LOG.info(
+ "%s's status updated to DELETED.",
+ show_client.__name__,
+ )
+ return
+ if int(time.time()) - start >= check_timeout:
+ message = (
+ '{name} {field} failed to update to DELETED or become not '
+ 'found (404) within the required time {timeout}. Current '
+ 'status of {name}: {status}'.format(
+ name=show_client.__name__,
+ timeout=check_timeout,
+ status=object_details[status_key],
+ field=status_key
+ ))
+ caller = test_utils.find_test_caller()
+ if caller:
+ message = '({caller}) {message}'.format(caller=caller,
+ message=message)
+ raise lib_exc.TimeoutException(message)
+
+ time.sleep(check_interval)