From e789dd29c48ee8ad2b10eeb9ff24725f0e696bed Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Fri, 1 Jul 2011 07:31:17 -0700 Subject: review fixes --- nova/exception.py | 4 ++-- nova/notifier/api.py | 14 +++++--------- nova/tests/test_exception.py | 7 ++++++- 3 files changed, 13 insertions(+), 12 deletions(-) (limited to 'nova') diff --git a/nova/exception.py b/nova/exception.py index ea590199c..6e277b68d 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -113,8 +113,8 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None, # propagated. temp_type = f.__name__ - notifier.safe_notify(publisher_id, temp_type, temp_level, - payload) + notifier.notify(publisher_id, temp_type, temp_level, + payload) if not isinstance(e, Error): #exc_type, exc_value, exc_traceback = sys.exc_info() diff --git a/nova/notifier/api.py b/nova/notifier/api.py index d388eda96..98969fd3e 100644 --- a/nova/notifier/api.py +++ b/nova/notifier/api.py @@ -45,14 +45,6 @@ def publisher_id(service, host=None): return "%s.%s" % (service, host) -def safe_notify(publisher_id, event_type, priority, payload): - try: - notify(publisher_id, event_type, notification_level, payload) - except Exception, e: - LOG.exception(_("Problem '%(e)s' attempting to " - "send to notification system." % locals())) - - def notify(publisher_id, event_type, priority, payload): """ Sends a notification using the specified driver @@ -95,4 +87,8 @@ def notify(publisher_id, event_type, priority, payload): priority=priority, payload=payload, timestamp=str(utils.utcnow())) - driver.notify(msg) + try: + driver.notify(msg) + except Exception, e: + LOG.exception(_("Problem '%(e)s' attempting to " + "send to notification system." % locals())) diff --git a/nova/tests/test_exception.py b/nova/tests/test_exception.py index 16e273f89..692b714e5 100644 --- a/nova/tests/test_exception.py +++ b/nova/tests/test_exception.py @@ -64,11 +64,16 @@ def bad_function_exception(): class WrapExceptionTestCase(test.TestCase): - def test_wrap_exception(self): + def test_wrap_exception_good_return(self): wrapped = exception.wrap_exception() self.assertEquals(99, wrapped(good_function)()) + + def test_wrap_exception_throws_error(self): + wrapped = exception.wrap_exception() self.assertRaises(exception.Error, wrapped(bad_function_error)) + def test_wrap_exception_throws_exception(self): + wrapped = exception.wrap_exception() # Note that Exception is converted to Error ... self.assertRaises(exception.Error, wrapped(bad_function_exception)) -- cgit