From 2c750b616ee81cf8a23f0a9a6695939b1bf7c72b Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 8 Jan 2025 11:51:21 +0000 Subject: [PATCH] [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 --- neutron/common/eventlet_utils.py | 9 +++++++++ neutron/notifiers/nova.py | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/neutron/common/eventlet_utils.py b/neutron/common/eventlet_utils.py index babc70cf70d..6036a90a0f8 100644 --- a/neutron/common/eventlet_utils.py +++ b/neutron/common/eventlet_utils.py @@ -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() diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py index 27dedc2d34d..67665b8fb6f 100644 --- a/neutron/notifiers/nova.py +++ b/neutron/notifiers/nova.py @@ -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