api: use oslo.config to validate data for worker

Change-Id: I526827e5f8bdb7fcb53e68999c4087d5dd14fb59
This commit is contained in:
Julien Danjou 2015-07-23 18:10:29 +02:00
parent 163328ee3b
commit e8717983dd
3 changed files with 4 additions and 21 deletions

View File

@ -27,7 +27,6 @@ from aodh.api import hooks
from aodh.api import middleware
from aodh.i18n import _
from aodh.i18n import _LW
from aodh import service
from aodh import storage
@ -41,6 +40,7 @@ OPTS = [
help="Configuration file for WSGI definition of API."
),
cfg.IntOpt('api_workers', default=1,
min=1,
help='Number of workers for aodh API server.'),
]
@ -74,7 +74,7 @@ def setup_app(pecan_config=None):
# NOTE(sileht): pecan debug won't work in multi-process environment
pecan_debug = CONF.api.pecan_debug
if service.get_workers('api') != 1 and pecan_debug:
if cfg.CONF.api_workers != 1 and pecan_debug:
pecan_debug = False
LOG.warning(_LW('pecan_debug cannot be enabled, if workers is > 1, '
'the value is overrided with False'))
@ -123,9 +123,8 @@ def build_server():
LOG.info(_("serving on http://%(host)s:%(port)s") % (
{'host': host, 'port': port}))
workers = service.get_workers('api')
serving.run_simple(cfg.CONF.api.host, cfg.CONF.api.port,
app, processes=workers)
app, processes=cfg.CONF.api_workers)
def _app():

View File

@ -32,7 +32,6 @@ from aodh.i18n import _
from aodh import messaging
from aodh import rpc
from aodh import storage
from aodh import utils
OPTS = [
@ -105,21 +104,6 @@ cfg.CONF.register_cli_opts(CLI_OPTS, group="service_credentials")
LOG = log.getLogger(__name__)
class WorkerException(Exception):
"""Exception for errors relating to service workers."""
def get_workers(name):
workers = (cfg.CONF.get('%s_workers' % name) or
utils.cpu_count())
if workers and workers < 1:
msg = (_("%(worker_name)s value of %(workers)s is invalid, "
"must be greater than 0") %
{'worker_name': '%s_workers' % name, 'workers': str(workers)})
raise WorkerException(msg)
return workers
def prepare_service(argv=None):
oslo_i18n.enable_lazy()
log.register_options(cfg.CONF)

View File

@ -10,7 +10,7 @@ keystonemiddleware>=1.5.0
lxml>=2.3
oslo.context>=0.2.0 # Apache-2.0
oslo.db>=1.12.0 # Apache-2.0
oslo.config>=1.11.0 # Apache-2.0
oslo.config>=1.15.0 # Apache-2.0
oslo.i18n>=1.5.0 # Apache-2.0
oslo.log>=1.2.0 # Apache-2.0
oslo.policy>=0.5.0 # Apache-2.0