Drop extra dns query
Use result from query loop
Related-PRODX: PRODX-51199
TODO: merge with I61c303145367293f09fcf4f4080dda99c8849633
Change-Id: Ia963234df19d7f8dd9ea2f5a2bcf012694e676ed
diff --git a/designate_tempest_plugin/common/waiters.py b/designate_tempest_plugin/common/waiters.py
index 72fe2a6..7e3ff80 100644
--- a/designate_tempest_plugin/common/waiters.py
+++ b/designate_tempest_plugin/common/waiters.py
@@ -305,3 +305,31 @@
message = '(%s) %s' % (caller, message)
raise lib_exc.TimeoutException(message)
+
+
+def wait_for_result(func, duration, sleep_for, *args, **kwargs):
+ """Call the given function until it returns result
+
+ or until the specified duration (in seconds) elapses (and return False).
+
+ :param func: A callable that returns True on success.
+ :param duration: The number of seconds for which to attempt a
+ successful call of the function.
+ :param sleep_for: The number of seconds to sleep after an unsuccessful
+ invocation of the function.
+ :param args: args that are passed to func.
+ :param kwargs: kwargs that are passed to func.
+ """
+ begin_time = time.time()
+ result = None
+ timeout = begin_time + duration
+ func_name = getattr(func, '__name__', getattr(func.__class__, '__name__'))
+ while time.time() < timeout:
+ result = func(*args, **kwargs)
+ if result:
+ LOG.debug("Call %s returns %s in %f seconds",
+ func_name, result, time.time() - begin_time)
+ return result
+ time.sleep(sleep_for)
+ LOG.debug("Call %s returns false in %f seconds", func_name, duration)
+ return result