Merge "Use pbr wsgi_scripts to build aodh-api"

This commit is contained in:
Jenkins 2016-07-18 10:32:35 +00:00 committed by Gerrit Code Review
commit 0578ade715
9 changed files with 10 additions and 94 deletions

View File

@ -17,14 +17,6 @@ from oslo_config import cfg
# Register options for the service
OPTS = [
cfg.PortOpt('port',
default=8042,
help='The port for the aodh API server.',
),
cfg.StrOpt('host',
default='0.0.0.0',
help='The listen IP for the aodh API server.',
),
cfg.StrOpt('paste_config',
default="api_paste.ini",
help="Configuration file for WSGI definition of API."),

View File

@ -1,6 +1,6 @@
#
# Copyright 2012 New Dream Network, LLC (DreamHost)
# Copyright 2015 Red Hat, Inc.
# Copyright 2015-2016 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@ -20,12 +20,9 @@ from oslo_config import cfg
from oslo_log import log
from paste import deploy
import pecan
from werkzeug import serving
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
@ -51,16 +48,9 @@ def setup_app(pecan_config=PECAN_CONFIG, conf=None):
pecan.configuration.set_config(dict(pecan_config), overwrite=True)
# NOTE(sileht): pecan debug won't work in multi-process environment
pecan_debug = conf.api.pecan_debug
if 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'))
app = pecan.make_app(
pecan_config['app']['root'],
debug=pecan_debug,
debug=conf.api.pecan_debug,
hooks=app_hooks,
wrap_app=middleware.ParsableErrorMiddleware,
guess_content_type_from_ext=False
@ -84,25 +74,8 @@ def load_app(conf):
return deploy.loadapp("config:" + cfg_file)
def build_server(conf):
app = load_app(conf)
# Create the WSGI server and start it
host, port = conf.api.host, conf.api.port
LOG.info(_('Starting server in PID %s') % os.getpid())
LOG.info(_("Configuration:"))
conf.log_opt_values(LOG, log.INFO)
if host == '0.0.0.0':
LOG.info(_(
'serving on 0.0.0.0:%(sport)s, view at http://127.0.0.1:%(vport)s')
% ({'sport': port, 'vport': port}))
else:
LOG.info(_("serving on http://%(host)s:%(port)s") % (
{'host': host, 'port': port}))
serving.run_simple(host, port,
app, processes=conf.api.workers)
def build_wsgi_app(argv=None):
return load_app(service.prepare_service(argv=argv))
def _app():

View File

@ -19,9 +19,5 @@
See http://pecan.readthedocs.org/en/latest/deployment.html for details.
"""
from aodh.api import app
from aodh import service
# Initialize the oslo configuration library and logging
conf = service.prepare_service([])
application = app.load_app(conf)
application = app.build_wsgi_app(argv=[])

View File

@ -1,24 +0,0 @@
# -*- encoding: utf-8 -*-
#
# Copyright 2014 OpenStack Foundation
# Copyright 2015 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from aodh.api import app
from aodh import service
def main():
conf = service.prepare_service()
app.build_server(conf)

View File

@ -35,25 +35,3 @@ class TestApp(base.BaseTestCase):
ff.return_value = None
self.assertRaises(cfg.ConfigFilesNotFoundError,
app.load_app, self.CONF)
@mock.patch('aodh.storage.get_connection_from_config',
mock.MagicMock())
@mock.patch('pecan.make_app')
def test_pecan_debug(self, mocked):
def _check_pecan_debug(g_debug, p_debug, expected, workers=1):
self.CONF.set_override('debug', g_debug)
if p_debug is not None:
self.CONF.set_override('pecan_debug', p_debug, group='api')
self.CONF.set_override('workers', workers, 'api')
app.setup_app(conf=self.CONF)
args, kwargs = mocked.call_args
self.assertEqual(expected, kwargs.get('debug'))
_check_pecan_debug(g_debug=False, p_debug=None, expected=False)
_check_pecan_debug(g_debug=True, p_debug=None, expected=False)
_check_pecan_debug(g_debug=True, p_debug=False, expected=False)
_check_pecan_debug(g_debug=False, p_debug=True, expected=True)
_check_pecan_debug(g_debug=True, p_debug=None, expected=False,
workers=5)
_check_pecan_debug(g_debug=False, p_debug=True, expected=False,
workers=5)

View File

@ -23,7 +23,7 @@ fi
if [ -z "$AODH_DEPLOY" ]; then
# Default
AODH_DEPLOY=werkzeug
AODH_DEPLOY=simple
# Fallback to common wsgi devstack configuration
if [ "$ENABLE_HTTPD_MOD_WSGI_SERVICES" == "True" ]; then

View File

@ -23,7 +23,7 @@ AODH_SERVICE_PORT=${AODH_SERVICE_PORT:-8042}
# AODH_DEPLOY defines how Aodh is deployed, allowed values:
# - mod_wsgi : Run Aodh under Apache HTTPd mod_wsgi
# - werkzeug : Run aodh-api
# - simple : Run aodh-api
# - uwsgi : Run Aodh under uwsgi
# - <empty>: Fallback to AODH_USE_MOD_WSGI or ENABLE_HTTPD_MOD_WSGI_SERVICES
AODH_DEPLOY=${AODH_DEPLOY}

View File

@ -29,7 +29,6 @@ requests>=2.5.2
six>=1.9.0
stevedore>=1.5.0 # Apache-2.0
tooz>=1.28.0 # Apache-2.0
Werkzeug>=0.7 # BSD License
WebOb>=1.2.3
WSME>=0.8
cotyledon

View File

@ -108,8 +108,10 @@ aodh.notifier =
trust+https = aodh.notifier.trust:TrustRestAlarmNotifier
zaqar = aodh.notifier.zaqar:ZaqarAlarmNotifier
wsgi_scripts =
aodh-api = aodh.api.app:build_wsgi_app
console_scripts =
aodh-api = aodh.cmd.api:main
aodh-dbsync = aodh.cmd.storage:dbsync
aodh-expirer = aodh.cmd.storage:expirer
aodh-evaluator = aodh.cmd.alarm:evaluator