diff --git a/nova/flags.py b/nova/flags.py index 4e6e3ad4..e9bf6e33 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -404,9 +404,10 @@ DEFINE_string('root_helper', 'sudo', 'Command prefix to use for running commands as root') DEFINE_bool('monkey_patch', False, - 'Whether to monkey patch') + 'Whether to log monkey patching') DEFINE_list('monkey_patch_modules', ['nova.api.ec2.cloud:nova.notifier.api.notify_decorator', 'nova.compute.api:nova.notifier.api.notify_decorator'], - 'Module list representing monkey patched module and decorator') + 'Module list representing monkey\ + patched module and decorator') diff --git a/nova/notifier/api.py b/nova/notifier/api.py index 99b8b010..a98f17db 100644 --- a/nova/notifier/api.py +++ b/nova/notifier/api.py @@ -40,6 +40,14 @@ class BadPriorityException(Exception): def notify_decorator(name, fn): + """ decorator for notify which is used from utils.monkey_patch() + Parameters: + + name - name of the function + function - object of the function + + + """ def wrapped_func(*args, **kwarg): body = {} body['args'] = [] diff --git a/nova/tests/test_notifier.py b/nova/tests/test_notifier.py index 64b799a2..ab5dfb69 100644 --- a/nova/tests/test_notifier.py +++ b/nova/tests/test_notifier.py @@ -134,3 +134,25 @@ class NotifierTestCase(test.TestCase): self.assertEqual(msg['event_type'], 'error_notification') self.assertEqual(msg['priority'], 'ERROR') self.assertEqual(msg['payload']['error'], 'foo') + + def test_send_notification_by_decorator(self): + self.notify_called = False + + def example_api(arg1, arg2): + return arg1 + arg2 + + example_api =\ + nova.notifier.api.notify_decorator( + 'example_api', + example_api) + + def mock_notify(cls, *args): + self.notify_called = True + + self.stubs.Set(nova.notifier.no_op_notifier, 'notify', + mock_notify) + + class Mock(object): + pass + self.assertEqual(3, example_api(1, 2)) + self.assertEqual(self.notify_called, True)