diff --git a/magnum/common/profiler.py b/magnum/common/profiler.py index a529df48e2..b24ebe755c 100644 --- a/magnum/common/profiler.py +++ b/magnum/common/profiler.py @@ -57,7 +57,7 @@ class WsgiMiddleware(object): def setup(binary, host): - if CONF.profiler.enabled: + if hasattr(CONF, 'profiler') and CONF.profiler.enabled: profiler_initializer.init_from_conf( conf=CONF, context=context.get_admin_context().to_dict(), diff --git a/magnum/tests/unit/common/test_profiler.py b/magnum/tests/unit/common/test_profiler.py index e68cd1ef4c..a21f9e5226 100644 --- a/magnum/tests/unit/common/test_profiler.py +++ b/magnum/tests/unit/common/test_profiler.py @@ -16,6 +16,7 @@ import inspect import mock +from oslo_config import cfg from oslo_utils import importutils from osprofiler import initializer as profiler_init from osprofiler import opts as profiler_opts @@ -73,3 +74,9 @@ class TestProfiler(base.TestCase): project="magnum", service='foo', host='localhost') + + @mock.patch.object(profiler_init, 'init_from_conf') + @mock.patch.object(conf, 'CONF', new=cfg.ConfigOpts()) + def test_setup_profiler_without_osprofiler(self, mock_init): + profiler.setup('foo', 'localhost') + self.assertFalse(mock_init.called)