From bdddbdf2defd5b8cd4996ee6163746571146ea7c Mon Sep 17 00:00:00 2001 From: Corey O'Brien Date: Fri, 24 Feb 2017 08:41:40 -0500 Subject: [PATCH] Remove reliance on osprofiler configuration section Change-Id: I5b06afc0da936c1def04375e9990a20b5d53c3e2 Closes-Bug: 1667417 Depends-On: Ia2881f5c6b84993850f2642c7a7f240ce6ad3f73 --- magnum/common/profiler.py | 2 +- magnum/tests/unit/common/test_profiler.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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)