diff options
author | Rodolfo Alonso Hernandez <ralonsoh@redhat.com> | 2022-01-29 10:10:22 +0000 |
---|---|---|
committer | Rodolfo Alonso <ralonsoh@redhat.com> | 2022-02-02 08:03:38 +0000 |
commit | 507989fc622a6633926c4288827f482bae6054dd (patch) | |
tree | 003baa7abff8d0f510bf7c0801c29cbf7950797a /neutron/notifiers | |
parent | e7b70521d0e230143a80974e7e4795a2acafcc9b (diff) | |
download | neutron-507989fc622a6633926c4288827f482bae6054dd.tar.gz |
Use a thread local variable to store the Nova Notifier enable flag
The Nova Notifier can be called simultaneously by several RPC
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. This will isolate the flag update
if two entities inform at the same time and one RPC callback is attended
during the processing of the other one.
This patch also removes the debug messages added to debug this issue.
Closes-Bug: #1958363
Change-Id: Ie670fba4b3afe427747732d2c3948d92311e960e
Diffstat (limited to 'neutron/notifiers')
-rw-r--r-- | neutron/notifiers/nova.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py index 0f45e9837a..a9b29b346f 100644 --- a/neutron/notifiers/nova.py +++ b/neutron/notifiers/nova.py @@ -15,6 +15,7 @@ import contextlib +from eventlet.green import threading from keystoneauth1 import loading as ks_loading from neutron_lib.callbacks import events from neutron_lib.callbacks import registry @@ -45,6 +46,13 @@ NEUTRON_NOVA_EVENT_STATUS_MAP = {constants.PORT_STATUS_ACTIVE: 'completed', constants.PORT_STATUS_DOWN: 'completed'} NOVA_API_VERSION = "2.1" +NOTIFIER_ENABLE_DEFAULT = True +# NOTE(ralonsoh): the Nova notifier can be called simultaneously by several RPC +# 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() + @registry.has_registry_receivers class Notifier(object): @@ -68,20 +76,14 @@ class Notifier(object): if ext.name == "server_external_events"] self.batch_notifier = batch_notifier.BatchNotifier( cfg.CONF.send_events_interval, self.send_events) - self._enabled = True @contextlib.contextmanager def context_enabled(self, enabled): - stored_enabled = self._enabled - LOG.debug("nova notifier stored_enabled: %s; enabled: %s", - stored_enabled, enabled) try: - self._enabled = enabled + _notifier_store.enable = enabled yield finally: - LOG.debug("Restoring value: %s for the _enabled flag.", - stored_enabled) - self._enabled = stored_enabled + _notifier_store.enable = NOTIFIER_ENABLE_DEFAULT def _get_nova_client(self): global_id = common_context.generate_request_id() @@ -180,7 +182,10 @@ class Notifier(object): return self._get_network_changed_event(port) def _can_notify(self, port): - if not self._enabled: + if getattr(_notifier_store, 'enable', None) is None: + _notifier_store.enable = NOTIFIER_ENABLE_DEFAULT + + if not _notifier_store.enable: LOG.debug("Nova notifier disabled") return False |