From 0dbe21cc8788a2aab8da79c551d137387c6e3f92 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Mon, 4 Jul 2016 11:38:55 +0300 Subject: [PATCH] Add a callback registry event for the init process - before spawning The current PROCESS AFTER_INIT event (or AFTER_CREATE) are being called multiple times, once for each process. In case we want to perform an action only once after init, we would need a callback that is called after init is done, but before spawning. Usage examples can be: - A plugin/driver needs to configure something at the backend after init is done - A plugin/driver needs to create an object in one of the neutron tables (add a network for example) Change-Id: I249ba32dede16e61b1c757a8010dac610484da4f --- neutron/callbacks/events.py | 3 ++- neutron/service.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/neutron/callbacks/events.py b/neutron/callbacks/events.py index a76bbae5c02..15f4c100cf8 100644 --- a/neutron/callbacks/events.py +++ b/neutron/callbacks/events.py @@ -31,7 +31,8 @@ AFTER_REQUEST = 'after_request' # String literals representing events associated to process operations BEFORE_INIT = 'before_init' -AFTER_INIT = 'after_init' +BEFORE_SPAWN = 'before_spawn' # sent per process +AFTER_INIT = 'after_init' # sent per worker # String literals representing events associated to error conditions ABORT_CREATE = 'abort_create' diff --git a/neutron/service.py b/neutron/service.py index d7308ecf3d4..236b3be2a3c 100644 --- a/neutron/service.py +++ b/neutron/service.py @@ -27,6 +27,9 @@ from oslo_utils import excutils from oslo_utils import importutils from neutron._i18n import _LE, _LI +from neutron.callbacks import events +from neutron.callbacks import registry +from neutron.callbacks import resources from neutron.common import config from neutron.common import profiler from neutron.common import rpc as n_rpc @@ -87,6 +90,7 @@ def serve_wsgi(cls): LOG.exception(_LE('Unrecoverable error: please check log ' 'for details.')) + registry.notify(resources.PROCESS, events.BEFORE_SPAWN, service) return service