use debug value for pecan_debug default
Currently, we declare pecan_debug with default=CONF.debug, but which only gets debug's default value. If debug is set to True, then pecan_debug remains False. That is because declaration happens in import time, which is before configuration file parsed. There are two choices: 1. set pecan_debug default to False, and user needs to enable it explicitly 2. set pecan_debug default to None, and if it is not set, then use global debug value This patch chooses the second one. Note: users who enable global debug while running ceilometer-api under mod_wsgi with multiple processes need to disable pecan_debug explicitly after this patch is merged, since previously the pecan_debug will always be False if they don't configure it. ref: Ib4a472e3c8d1f34f64a5f3ab993c1211dee8af9a DocImpact Change-Id: I9436dbef2272f7b1de769dcb835365f8eb0feeca
This commit is contained in:
parent
a3a4e0e283
commit
c69925436e
@ -43,9 +43,8 @@ OPTS = [
|
||||
|
||||
API_OPTS = [
|
||||
cfg.BoolOpt('pecan_debug',
|
||||
default=CONF.debug,
|
||||
help='Toggle Pecan Debug Middleware. '
|
||||
'Defaults to global debug value.'
|
||||
'If it is not set, global debug value will be used.'
|
||||
),
|
||||
]
|
||||
|
||||
@ -76,6 +75,8 @@ def setup_app(pecan_config=None, extra_hooks=None):
|
||||
|
||||
pecan.configuration.set_config(dict(pecan_config), overwrite=True)
|
||||
|
||||
cfg.set_defaults(API_OPTS, pecan_debug=CONF.debug)
|
||||
|
||||
app = pecan.make_app(
|
||||
pecan_config.app.root,
|
||||
debug=CONF.api.pecan_debug,
|
||||
@ -91,7 +92,6 @@ def setup_app(pecan_config=None, extra_hooks=None):
|
||||
class VersionSelectorApplication(object):
|
||||
def __init__(self):
|
||||
pc = get_pecan_config()
|
||||
pc.app.debug = CONF.api.pecan_debug
|
||||
|
||||
def not_found(environ, start_response):
|
||||
start_response('404 Not Found', [])
|
||||
|
@ -49,3 +49,21 @@ class TestApp(base.BaseTestCase):
|
||||
with mock.patch.object(self.CONF, 'find_file') as ff:
|
||||
ff.return_value = None
|
||||
self.assertRaises(cfg.ConfigFilesNotFoundError, app.load_app)
|
||||
|
||||
@mock.patch('ceilometer.storage.get_connection_from_config',
|
||||
mock.MagicMock())
|
||||
@mock.patch('ceilometer.api.hooks.PipelineHook', mock.MagicMock())
|
||||
@mock.patch('pecan.make_app')
|
||||
def test_pecan_debug(self, mocked):
|
||||
def _check_pecan_debug(g_debug, p_debug, expected):
|
||||
self.CONF.set_override('debug', g_debug)
|
||||
if p_debug is not None:
|
||||
self.CONF.set_override('pecan_debug', p_debug, group='api')
|
||||
app.setup_app()
|
||||
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=True)
|
||||
_check_pecan_debug(g_debug=True, p_debug=False, expected=False)
|
||||
_check_pecan_debug(g_debug=False, p_debug=True, expected=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user