From 858494997e059fc29e374443e39f0222a1df8173 Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Tue, 27 May 2025 15:05:53 +0200 Subject: [PATCH] Centralize cooperative yield Replace the remaining time.sleep calls use to trigger eventlet yield to the existing nova.utils.cooperative_yield() call. This will help us to disable such yielding in when the service is running in threading mode and eventually drop the whole thing when nova removes eventlet. Change-Id: I6b3fcba13f4d1c41d1fac2efe3cb4a943e66f8bb Signed-off-by: Balazs Gibizer --- nova/scheduler/host_manager.py | 4 +--- nova/tests/unit/virt/disk/mount/test_nbd.py | 4 ++-- nova/virt/libvirt/driver.py | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py index f448c8140f31..f49c76326ac5 100644 --- a/nova/scheduler/host_manager.py +++ b/nova/scheduler/host_manager.py @@ -19,7 +19,6 @@ Manage hosts in the current zone. import collections import functools -import time import iso8601 from oslo_log import log as logging @@ -465,8 +464,7 @@ class HostManager(object): "updated": False} inst_dict = self._instance_info[host] inst_dict["instances"][instance.uuid] = instance - # Call sleep() to cooperatively yield - time.sleep(0) + utils.cooperative_yield() LOG.debug("END:_async_init_instance_info") # Run this async so that we don't block the scheduler start-up diff --git a/nova/tests/unit/virt/disk/mount/test_nbd.py b/nova/tests/unit/virt/disk/mount/test_nbd.py index cc0e04337ecf..707cff25017f 100644 --- a/nova/tests/unit/virt/disk/mount/test_nbd.py +++ b/nova/tests/unit/virt/disk/mount/test_nbd.py @@ -16,13 +16,13 @@ import os import tempfile -import time from unittest import mock import eventlet import fixtures from nova import test +from nova import utils from nova.virt.disk.mount import nbd from nova.virt.image import model as imgmodel @@ -304,7 +304,7 @@ class NbdTestCase(test.NoDBTestCase): # Ensure that context switch happens before the device is marked # as used. This will cause a failure without nbd-allocation-lock # in place. - time.sleep(0.1) + utils.cooperative_yield() # We always choose the top device in find_unused - remove it now. free_devices.pop() diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 4375dc754b60..f196ebebc4de 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -11537,7 +11537,7 @@ class LibvirtDriver(driver.ComputeDriver): future.add_done_callback(thread_finished) # Let eventlet schedule the new thread right away - time.sleep(0) + utils.cooperative_yield() try: LOG.debug("Starting monitoring of live migration",