Stop using osprofiler options as if they are part of public API

Options are for operators, not for the code. We should switch to public
functions provided by the library, to get what we want.

Change-Id: Id124dc6743d83c62d264ecc6b01a6b4006e44f35
This commit is contained in:
Ihar Hrachyshka 2016-11-08 20:05:25 +00:00
parent e727b92d3d
commit f90eefc20c
2 changed files with 12 additions and 10 deletions

View File

@ -36,7 +36,8 @@ from neutron._i18n import _LE
def set_hook(engine):
if cfg.CONF.profiler.enabled and cfg.CONF.profiler.trace_sqlalchemy:
if (profiler_opts.is_trace_enabled() and
profiler_opts.is_db_trace_enabled()):
osprofiler.sqlalchemy.add_tracing(sqlalchemy, engine, 'neutron.db')

View File

@ -14,7 +14,6 @@
import mock
from neutron_lib import exceptions
from oslo_config import cfg
from oslo_db import exception as db_exc
import osprofiler
import sqlalchemy
@ -164,11 +163,13 @@ class TestDeadLockDecorator(base.BaseTestCase):
class TestCommonDBfunctions(base.BaseTestCase):
def test_set_hook(self):
with mock.patch.object(osprofiler.sqlalchemy,
'add_tracing') as profiler:
cfg.CONF.set_override('enabled', True, group='profiler')
cfg.CONF.set_override('trace_sqlalchemy', True, group='profiler')
engine_mock = mock.Mock()
db_api.set_hook(engine_mock)
profiler.assert_called_with(sqlalchemy, engine_mock,
'neutron.db')
with mock.patch.object(osprofiler.opts, 'is_trace_enabled',
return_value=True),\
mock.patch.object(osprofiler.opts, 'is_db_trace_enabled',
return_value=True):
with mock.patch.object(osprofiler.sqlalchemy,
'add_tracing') as add_tracing:
engine_mock = mock.Mock()
db_api.set_hook(engine_mock)
add_tracing.assert_called_with(sqlalchemy, engine_mock,
'neutron.db')