Adapt wait_until_true

The code is copy&pasted from Neutron tree. This patch copies what
the Neutron patch [1] removing eventlet from wait_until_true does.

[1] https://review.opendev.org/c/openstack/neutron/+/937843

Change-Id: Ib8caf3140aed22da40bbe48518df5a1ca2ecf8d1
Signed-off-by: Jakub Libosvar <libosvar@redhat.com>
This commit is contained in:
Jakub Libosvar
2025-08-14 07:46:41 -04:00
parent ccf4c29b14
commit d9b0b54ec3

View File

@@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import eventlet
import time
import uuid
@@ -52,12 +52,12 @@ def wait_until_true(predicate, timeout=60, sleep=1, exception=None):
:param exception: Exception instance to raise on timeout. If None is passed
(default) then WaitTimeout exception is raised.
"""
try:
with eventlet.Timeout(timeout):
while not predicate():
eventlet.sleep(sleep)
except eventlet.Timeout:
if exception is not None:
# pylint: disable=raising-bad-type
raise exception
raise WaitTimeout('Timed out after %d seconds' % timeout)
start_time = time.time()
while not predicate():
elapsed_time = time.time() - start_time
if elapsed_time > timeout:
raise exception if exception else WaitTimeout(
_("Timed out after %d seconds") % timeout
)
time.sleep(sleep)