diff options
author | Phil Day <philip.day@hp.com> | 2013-01-31 12:55:19 +0000 |
---|---|---|
committer | Phil Day <philip.day@hp.com> | 2013-02-04 16:57:45 +0000 |
commit | 9deabd21f49cd986b642d5f3718d6285da83e8bb (patch) | |
tree | b8f93c2dc9d55b3221be08bd59dd85750b519842 | |
parent | 194ec6204ee3a67193b1ffd63de073d50878ce77 (diff) | |
download | nova-9deabd21f49cd986b642d5f3718d6285da83e8bb.tar.gz nova-9deabd21f49cd986b642d5f3718d6285da83e8bb.tar.xz nova-9deabd21f49cd986b642d5f3718d6285da83e8bb.zip |
Default value of monkey_patch_modules is broken
The default value of monkey_patch_modules has not kept up with
the move of notifier to openstack.common
Without this change setting 'monkey_patch=True' in nova.conf
will cause runtime errors unless the monkey_patch_modules
is also specified pointing to the correct notifier
Change-Id: Ib22faa7404b09791799338de2edfe0ddcd662d5f
-rw-r--r-- | nova/tests/test_utils.py | 27 | ||||
-rw-r--r-- | nova/utils.py | 11 |
2 files changed, 34 insertions, 4 deletions
diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py index 84d56cadf..723d6ab58 100644 --- a/nova/tests/test_utils.py +++ b/nova/tests/test_utils.py @@ -17,6 +17,7 @@ import __builtin__ import datetime import hashlib +import importlib import os import os.path import StringIO @@ -26,10 +27,13 @@ import mox import nova from nova import exception +from nova.openstack.common import cfg from nova.openstack.common import timeutils from nova import test from nova import utils +CONF = cfg.CONF + class ByteConversionTest(test.TestCase): def test_string_conversions(self): @@ -509,6 +513,29 @@ class MonkeyPatchTestCase(test.TestCase): in nova.tests.monkey_patch_example.CALLED_FUNCTION) +class MonkeyPatchDefaultTestCase(test.TestCase): + """Unit test for default monkey_patch_modules value.""" + + def setUp(self): + super(MonkeyPatchDefaultTestCase, self).setUp() + self.flags( + monkey_patch=True) + + def test_monkey_patch_default_mod(self): + # monkey_patch_modules is defined to be + # <module_to_patch>:<decorator_to_patch_with> + # Here we check that both parts of the default values are + # valid + for module in CONF.monkey_patch_modules: + m = module.split(':', 1) + # Check we can import the module to be patched + importlib.import_module(m[0]) + # check the decorator is valid + decorator_name = m[1].rsplit('.', 1) + decorator_module = importlib.import_module(decorator_name[0]) + getattr(decorator_module, decorator_name[1]) + + class AuditPeriodTest(test.TestCase): def setUp(self): diff --git a/nova/utils.py b/nova/utils.py index de9879393..738b10f37 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -50,14 +50,16 @@ from nova.openstack.common import importutils from nova.openstack.common import log as logging from nova.openstack.common import timeutils +notify_decorator = 'nova.openstack.common.notifier.api.notify_decorator' + monkey_patch_opts = [ cfg.BoolOpt('monkey_patch', default=False, help='Whether to log monkey patching'), cfg.ListOpt('monkey_patch_modules', default=[ - 'nova.api.ec2.cloud:nova.notifier.api.notify_decorator', - 'nova.compute.api:nova.notifier.api.notify_decorator' + 'nova.api.ec2.cloud:%s' % (notify_decorator), + 'nova.compute.api:%s' % (notify_decorator) ], help='List of modules/decorators to monkey patch'), ] @@ -930,10 +932,11 @@ def monkey_patch(): You can set decorators for each modules using CONF.monkey_patch_modules. The format is "Module path:Decorator function". - Example: 'nova.api.ec2.cloud:nova.notifier.api.notify_decorator' + Example: + 'nova.api.ec2.cloud:nova.openstack.common.notifier.api.notify_decorator' Parameters of the decorator is as follows. - (See nova.notifier.api.notify_decorator) + (See nova.openstack.common.notifier.api.notify_decorator) name - name of the function function - object of the function |