diff options
| author | Tim Simpson <tim.simpson@rackspace.com> | 2011-08-23 13:12:54 -0500 |
|---|---|---|
| committer | Tim Simpson <tim.simpson@rackspace.com> | 2011-08-23 13:12:54 -0500 |
| commit | b75f90e0d83e50b6699a8e6efc60cc97a00c0678 (patch) | |
| tree | 1f26dc90d5b4351cd16b66c7e4a1136c4199a487 | |
| parent | 5c4d35f94f5bb85b2140b0d68e545b5c23725f56 (diff) | |
Switched list_notifier to log an exception each time notify is called, for each notification driver that failed to import.
| -rw-r--r-- | nova/notifier/list_notifier.py | 13 | ||||
| -rw-r--r-- | nova/tests/notifier/test_list_notifier.py | 10 |
2 files changed, 12 insertions, 11 deletions
diff --git a/nova/notifier/list_notifier.py b/nova/notifier/list_notifier.py index 21067df55..aa9c236b0 100644 --- a/nova/notifier/list_notifier.py +++ b/nova/notifier/list_notifier.py @@ -30,6 +30,15 @@ LOG = logging.getLogger('nova.notifier.list_notifier') 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(): """Instantiates and returns drivers based on the flag values.""" @@ -39,8 +48,8 @@ def _get_drivers(): for notification_driver in FLAGS.list_notifier_drivers: try: drivers.append(utils.import_object(notification_driver)) - except ClassNotFound: - sys.exit(1) + except ClassNotFound as e: + drivers.append(ImportFailureNotifier(e)) return drivers def notify(message): diff --git a/nova/tests/notifier/test_list_notifier.py b/nova/tests/notifier/test_list_notifier.py index bab1a0ab8..ad2b039c5 100644 --- a/nova/tests/notifier/test_list_notifier.py +++ b/nova/tests/notifier/test_list_notifier.py @@ -48,11 +48,6 @@ class NotifierListTestCase(test.TestCase): def mock_notify2(cls, *args): raise RuntimeError("Bad notifier.") 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): self.stubs.UnsetAll() @@ -67,7 +62,6 @@ class NotifierListTestCase(test.TestCase): nova.notifier.api.WARN, dict(a=3)) self.assertEqual(self.notify_count, 2) self.assertEqual(self.exception_count, 0) - self.assertEqual(self.sys_exit_code, 0) 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)) self.assertEqual(self.notify_count, 1) self.assertEqual(self.exception_count, 1) - self.assertEqual(self.sys_exit_code, 0) def test_when_driver_fails_to_import(self): self.flags(notification_driver='nova.notifier.list_notifier', @@ -85,6 +78,5 @@ class NotifierListTestCase(test.TestCase): 'nova.notifier.logo_notifier', 'fdsjgsdfhjkhgsfkj']) 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.sys_exit_code, 2) |
