Switched list_notifier to log an exception each time notify is called, for each notification driver that failed to import.
This commit is contained in:
@@ -30,6 +30,15 @@ LOG = logging.getLogger('nova.notifier.list_notifier')
|
|||||||
|
|
||||||
drivers = None
|
drivers = None
|
||||||
|
|
||||||
|
class ImportFailureNotifier(object):
|
||||||
|
"""Noisily re-raises some exception over-and-over when notify is called."""
|
||||||
|
|
||||||
|
def __init__(self, exception):
|
||||||
|
self.exception = exception
|
||||||
|
|
||||||
|
def notify(message):
|
||||||
|
raise self.exception
|
||||||
|
|
||||||
|
|
||||||
def _get_drivers():
|
def _get_drivers():
|
||||||
"""Instantiates and returns drivers based on the flag values."""
|
"""Instantiates and returns drivers based on the flag values."""
|
||||||
@@ -39,8 +48,8 @@ def _get_drivers():
|
|||||||
for notification_driver in FLAGS.list_notifier_drivers:
|
for notification_driver in FLAGS.list_notifier_drivers:
|
||||||
try:
|
try:
|
||||||
drivers.append(utils.import_object(notification_driver))
|
drivers.append(utils.import_object(notification_driver))
|
||||||
except ClassNotFound:
|
except ClassNotFound as e:
|
||||||
sys.exit(1)
|
drivers.append(ImportFailureNotifier(e))
|
||||||
return drivers
|
return drivers
|
||||||
|
|
||||||
def notify(message):
|
def notify(message):
|
||||||
|
|||||||
@@ -48,11 +48,6 @@ class NotifierListTestCase(test.TestCase):
|
|||||||
def mock_notify2(cls, *args):
|
def mock_notify2(cls, *args):
|
||||||
raise RuntimeError("Bad notifier.")
|
raise RuntimeError("Bad notifier.")
|
||||||
self.stubs.Set(nova.notifier.log_notifier, 'notify', mock_notify2)
|
self.stubs.Set(nova.notifier.log_notifier, 'notify', mock_notify2)
|
||||||
# mock sys.exit so we don't actually kill the program during our tests.
|
|
||||||
self.sys_exit_code = 0
|
|
||||||
def mock_sys_exit(code):
|
|
||||||
self.sys_exit_code += code
|
|
||||||
self.stubs.Set(sys, 'exit', mock_sys_exit)
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.stubs.UnsetAll()
|
self.stubs.UnsetAll()
|
||||||
@@ -67,7 +62,6 @@ class NotifierListTestCase(test.TestCase):
|
|||||||
nova.notifier.api.WARN, dict(a=3))
|
nova.notifier.api.WARN, dict(a=3))
|
||||||
self.assertEqual(self.notify_count, 2)
|
self.assertEqual(self.notify_count, 2)
|
||||||
self.assertEqual(self.exception_count, 0)
|
self.assertEqual(self.exception_count, 0)
|
||||||
self.assertEqual(self.sys_exit_code, 0)
|
|
||||||
|
|
||||||
def test_send_notifications_with_errors(self):
|
def test_send_notifications_with_errors(self):
|
||||||
|
|
||||||
@@ -77,7 +71,6 @@ class NotifierListTestCase(test.TestCase):
|
|||||||
notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3))
|
notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3))
|
||||||
self.assertEqual(self.notify_count, 1)
|
self.assertEqual(self.notify_count, 1)
|
||||||
self.assertEqual(self.exception_count, 1)
|
self.assertEqual(self.exception_count, 1)
|
||||||
self.assertEqual(self.sys_exit_code, 0)
|
|
||||||
|
|
||||||
def test_when_driver_fails_to_import(self):
|
def test_when_driver_fails_to_import(self):
|
||||||
self.flags(notification_driver='nova.notifier.list_notifier',
|
self.flags(notification_driver='nova.notifier.list_notifier',
|
||||||
@@ -85,6 +78,5 @@ class NotifierListTestCase(test.TestCase):
|
|||||||
'nova.notifier.logo_notifier',
|
'nova.notifier.logo_notifier',
|
||||||
'fdsjgsdfhjkhgsfkj'])
|
'fdsjgsdfhjkhgsfkj'])
|
||||||
notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3))
|
notify('publisher_id', 'event_type', nova.notifier.api.WARN, dict(a=3))
|
||||||
self.assertEqual(self.exception_count, 0)
|
self.assertEqual(self.exception_count, 2)
|
||||||
self.assertEqual(self.notify_count, 1)
|
self.assertEqual(self.notify_count, 1)
|
||||||
self.assertEqual(self.sys_exit_code, 2)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user