Browse Source

Register cleanup hooks for the object change handlers only when needed

In patch [1] there was added threads for the object change handlers and
this patch also added cleanup method which was registered to be linked
with the SIGINT, SIGTERM and run "atexit" to clean all object change
handler threads. But that cleanup was linked with those signals always
when neutron.plugins.ml2.ovo_rpc module was imported and that can cause
e.g. some errors in the functional tests (we saw them only in the
stable/train branch so far but maybe it can happen also in other
branches).
To avoid that, this patch links cleanup with those signals only when
object change handler threads are really started.

Related-Bug: #1926417

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

Change-Id: I40b72316bd0f4281484d3cf07542177297028e34
(cherry picked from commit bbc5af1166)
changes/74/824874/1
Slawek Kaplonski 4 months ago
parent
commit
77afc56e10
  1. 12
      neutron/plugins/ml2/ovo_rpc.py

12
neutron/plugins/ml2/ovo_rpc.py

@ -36,6 +36,12 @@ from neutron.objects import subnet
LOG = logging.getLogger(__name__)
def _setup_change_handlers_cleanup():
atexit.register(_ObjectChangeHandler.clean_up)
signal.signal(signal.SIGINT, _ObjectChangeHandler.clean_up)
signal.signal(signal.SIGTERM, _ObjectChangeHandler.clean_up)
class _ObjectChangeHandler(object):
MAX_IDLE_FOR = 1
_TO_CLEAN = weakref.WeakSet()
@ -158,6 +164,7 @@ class OVOServerRpcInterface(object):
def __init__(self):
self._rpc_pusher = resources_rpc.ResourcesPushRpcApi()
self._setup_change_handlers()
_setup_change_handlers_cleanup()
LOG.debug("ML2 OVO RPC backend initialized.")
def _setup_change_handlers(self):
@ -178,8 +185,3 @@ class OVOServerRpcInterface(object):
"""Wait for all handlers to finish processing async events."""
for handler in self._resource_handlers.values():
handler.wait()
atexit.register(_ObjectChangeHandler.clean_up)
signal.signal(signal.SIGINT, _ObjectChangeHandler.clean_up)
signal.signal(signal.SIGTERM, _ObjectChangeHandler.clean_up)

Loading…
Cancel
Save