Allow neutron-api load config from WSGI process
neutron-api needs to load config files when deployed under WSGI process. This patch will do this. neutron-rpc-server also need to be aware of plugin extension. uWSGI seems not happy with eventlet.GreenPool. So this patch will switch to futurist.ThreadPoolExcutor for ML2 OVO push notification. Partially-implements: blueprint run-in-wsgi-server Change-Id: Ia2659c9c8f1deeceefc1c75f1149a1e47c91e7a9 Closes-Bug: #1708389
This commit is contained in:
parent
ca13e651c9
commit
2f98f56cb5
@ -28,6 +28,7 @@ from oslo_middleware import cors
|
||||
from oslo_service import wsgi
|
||||
|
||||
from neutron._i18n import _
|
||||
from neutron.common import rpc as n_rpc
|
||||
from neutron.conf import common as common_config
|
||||
from neutron import policy
|
||||
from neutron import version
|
||||
@ -72,14 +73,12 @@ common_config.register_placement_opts()
|
||||
logging.register_options(cfg.CONF)
|
||||
|
||||
|
||||
def init(args, **kwargs):
|
||||
def init(args, default_config_files=None, **kwargs):
|
||||
cfg.CONF(args=args, project='neutron',
|
||||
version='%%(prog)s %s' % version.version_info.release_string(),
|
||||
default_config_files=default_config_files,
|
||||
**kwargs)
|
||||
|
||||
# FIXME(ihrachys): if import is put in global, circular import
|
||||
# failure occurs
|
||||
from neutron.common import rpc as n_rpc
|
||||
n_rpc.init(cfg.CONF)
|
||||
|
||||
# Validate that the base_mac is of the correct format
|
||||
@ -119,6 +118,10 @@ def load_paste_app(app_name):
|
||||
:param app_name: Name of the application to load
|
||||
"""
|
||||
loader = wsgi.Loader(cfg.CONF)
|
||||
|
||||
# Log the values of registered opts
|
||||
if cfg.CONF.debug:
|
||||
cfg.CONF.log_opt_values(LOG, logging.DEBUG)
|
||||
app = loader.load_app(app_name)
|
||||
return app
|
||||
|
||||
|
@ -13,7 +13,9 @@
|
||||
|
||||
import traceback
|
||||
|
||||
import eventlet
|
||||
import futurist
|
||||
from futurist import waiters
|
||||
|
||||
from neutron_lib.callbacks import events
|
||||
from neutron_lib.callbacks import registry
|
||||
from neutron_lib.callbacks import resources
|
||||
@ -38,7 +40,12 @@ class _ObjectChangeHandler(object):
|
||||
self._obj_class = object_class
|
||||
self._resource_push_api = resource_push_api
|
||||
self._resources_to_push = {}
|
||||
self._worker_pool = eventlet.GreenPool()
|
||||
|
||||
# NOTE(annp): uWSGI seems not happy with eventlet.GreenPool.
|
||||
# So switching to ThreadPool
|
||||
self._worker_pool = futurist.ThreadPoolExecutor()
|
||||
self.fts = []
|
||||
|
||||
self._semantic_warned = False
|
||||
for event in (events.AFTER_CREATE, events.AFTER_UPDATE,
|
||||
events.AFTER_DELETE):
|
||||
@ -46,7 +53,9 @@ class _ObjectChangeHandler(object):
|
||||
|
||||
def wait(self):
|
||||
"""Waits for all outstanding events to be dispatched."""
|
||||
self._worker_pool.waitall()
|
||||
done, not_done = waiters.wait_for_all(self.fts)
|
||||
if not not_done:
|
||||
del self.fts[:]
|
||||
|
||||
def _is_session_semantic_violated(self, context, resource, event):
|
||||
"""Return True and print an ugly error on transaction violation.
|
||||
@ -82,7 +91,7 @@ class _ObjectChangeHandler(object):
|
||||
# to the server-side event that triggered it
|
||||
self._resources_to_push[resource_id] = context.to_dict()
|
||||
# spawn worker so we don't block main AFTER_UPDATE thread
|
||||
self._worker_pool.spawn(self.dispatch_events)
|
||||
self.fts.append(self._worker_pool.submit(self.dispatch_events))
|
||||
|
||||
@lockutils.synchronized('event-dispatch')
|
||||
def dispatch_events(self):
|
||||
|
@ -16,6 +16,7 @@
|
||||
# If ../neutron/__init__.py exists, add ../ to Python search path, so that
|
||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
from oslo_config import cfg
|
||||
@ -24,10 +25,35 @@ from neutron._i18n import _
|
||||
from neutron.common import config
|
||||
from neutron.common import profiler
|
||||
|
||||
# NOTE(annp): These environment variables are required for deploying
|
||||
# neutron-api under mod_wsgi. Currently, these variables are set as DevStack's
|
||||
# default. If you intend to use other tools for deploying neutron-api under
|
||||
# mod_wsgi, you should export these variables with your values.
|
||||
|
||||
NEUTRON_CONF = 'neutron.conf'
|
||||
NEUTRON_CONF_DIR = '/etc/neutron/'
|
||||
NEUTRON_PLUGIN_CONF = 'plugins/ml2/ml2_conf.ini'
|
||||
|
||||
|
||||
def _get_config_files(env=None):
|
||||
if env is None:
|
||||
env = os.environ
|
||||
dirname = env.get('OS_NEUTRON_CONFIG_DIR', NEUTRON_CONF_DIR).strip()
|
||||
|
||||
files = [s.strip() for s in
|
||||
env.get('OS_NEUTRON_CONFIG_FILES', '').split(';') if s.strip()]
|
||||
|
||||
if not files:
|
||||
files = [NEUTRON_CONF, NEUTRON_PLUGIN_CONF]
|
||||
|
||||
return [os.path.join(dirname, fname) for fname in files]
|
||||
|
||||
|
||||
def _init_configuration():
|
||||
# the configuration will be read into the cfg.CONF global data structure
|
||||
config.init(sys.argv[1:])
|
||||
conf_files = _get_config_files()
|
||||
|
||||
config.init(sys.argv[1:], default_config_files=conf_files)
|
||||
config.setup_logging()
|
||||
config.set_config_defaults()
|
||||
if not cfg.CONF.config_file:
|
||||
|
@ -18,8 +18,10 @@
|
||||
# If ../neutron/__init__.py exists, add ../ to Python search path, so that
|
||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||
|
||||
from neutron_lib.api import attributes
|
||||
from oslo_log import log
|
||||
|
||||
from neutron.api import extensions
|
||||
from neutron import manager
|
||||
from neutron import service
|
||||
|
||||
@ -31,7 +33,9 @@ def eventlet_rpc_server():
|
||||
|
||||
try:
|
||||
manager.init()
|
||||
rpc_workers_launcher = service.start_all_workers()
|
||||
ext_mgr = extensions.PluginAwareExtensionManager.get_instance()
|
||||
ext_mgr.extend_resources("2.0", attributes.RESOURCES)
|
||||
rpc_workers_launcher = service.start_rpc_workers()
|
||||
except NotImplementedError:
|
||||
LOG.info("RPC was already started in parent process by "
|
||||
"plugin.")
|
||||
|
@ -269,9 +269,10 @@ def start_all_workers():
|
||||
|
||||
def start_rpc_workers():
|
||||
rpc_workers = _get_rpc_workers()
|
||||
|
||||
LOG.debug('using launcher for rpc, workers=%s', cfg.CONF.rpc_workers)
|
||||
return _start_workers(rpc_workers)
|
||||
launcher = _start_workers(rpc_workers)
|
||||
registry.publish(resources.PROCESS, events.AFTER_SPAWN, None)
|
||||
return launcher
|
||||
|
||||
|
||||
def start_plugins_workers():
|
||||
|
Loading…
Reference in New Issue
Block a user