[eventlet-deprecation] Nova notifier retrieves local thread

A new method to retrieve the local thread is implemented, depending
if the ``thread`` module is monkey patched or not. This is used
in the Nova notifier during the eventlet deprecation migration.

Related-Bug: #2087953
Change-Id: Icc7095d8485acee06cf602ccbf899be22dfc7a53
This commit is contained in:
Rodolfo Alonso Hernandez 2025-01-08 11:51:21 +00:00
parent 8a75a54707
commit 2c750b616e
2 changed files with 11 additions and 2 deletions

View File

@ -14,8 +14,11 @@
# under the License.
import os
import threading
import eventlet
from eventlet.green import threading as threading_eventlet
from oslo_utils import eventletutils
IS_MONKEY_PATCHED = False
@ -38,3 +41,9 @@ def monkey_patch():
p_c_e = importutils.import_module('pyroute2.config.asyncio')
p_c_e.asyncio_config()
IS_MONKEY_PATCHED = True
def get_threading_local():
if eventletutils.is_monkey_patched('thread'):
return threading_eventlet.local()
return threading.local()

View File

@ -15,7 +15,6 @@
import contextlib
from eventlet.green import threading
from keystoneauth1 import exceptions as ks_exceptions
from keystoneauth1 import loading as ks_loading
from neutron_lib.callbacks import events
@ -35,6 +34,7 @@ from oslo_utils import uuidutils
from sqlalchemy.orm import attributes as sql_attr
import tenacity
from neutron.common import eventlet_utils
from neutron.notifiers import batch_notifier
@ -53,7 +53,7 @@ NOTIFIER_ENABLE_DEFAULT = True
# callbacks from the agents (DHCP, L2), trying to update the provisioning
# status of a port. In order to handle each context notifier enable flag, a
# thread local variable is used.
_notifier_store = threading.local()
_notifier_store = eventlet_utils.get_threading_local()
@registry.has_registry_receivers