diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-07-18 12:35:19 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-07-18 12:35:19 +0000 |
| commit | 79b8840f5e6ac95f850cbc1236bfebffb5e1349f (patch) | |
| tree | 99d73359d15e3da6ad16adbc8c29f8f6a7ec8684 | |
| parent | b4148c2b88069f50eb0b215daf71d798fd0d892c (diff) | |
| parent | 593aa3db3d94a1cd8024a64b7af865387483c21e (diff) | |
| download | oslo-79b8840f5e6ac95f850cbc1236bfebffb5e1349f.tar.gz oslo-79b8840f5e6ac95f850cbc1236bfebffb5e1349f.tar.xz oslo-79b8840f5e6ac95f850cbc1236bfebffb5e1349f.zip | |
Merge "Remove the unused notifier.add_driver() API"
| -rw-r--r-- | openstack/common/notifier/api.py | 27 | ||||
| -rw-r--r-- | tests/unit/test_notifier.py | 37 |
2 files changed, 7 insertions, 57 deletions
diff --git a/openstack/common/notifier/api.py b/openstack/common/notifier/api.py index df89f67..edc1b4a 100644 --- a/openstack/common/notifier/api.py +++ b/openstack/common/notifier/api.py @@ -157,29 +157,16 @@ def _get_drivers(): if _drivers is None: _drivers = {} for notification_driver in CONF.notification_driver: - add_driver(notification_driver) - + try: + driver = importutils.import_module(notification_driver) + _drivers[notification_driver] = driver + except ImportError: + LOG.exception(_("Failed to load notifier %s. " + "These notifications will not be sent.") % + notification_driver) return _drivers.values() -def add_driver(notification_driver): - """Add a notification driver at runtime.""" - # Make sure the driver list is initialized. - _get_drivers() - if isinstance(notification_driver, basestring): - # Load and add - try: - driver = importutils.import_module(notification_driver) - _drivers[notification_driver] = driver - except ImportError: - LOG.exception(_("Failed to load notifier %s. " - "These notifications will not be sent.") % - notification_driver) - else: - # Driver is already loaded; just add the object. - _drivers[notification_driver] = notification_driver - - def _reset_drivers(): """Used by unit tests to reset the drivers.""" global _drivers diff --git a/tests/unit/test_notifier.py b/tests/unit/test_notifier.py index 891b0ec..da0d78a 100644 --- a/tests/unit/test_notifier.py +++ b/tests/unit/test_notifier.py @@ -202,14 +202,6 @@ class NotifierTestCase(test_utils.BaseTestCase): self.assertEqual(self.context_arg, None) -class SimpleNotifier(object): - def __init__(self): - self.notified = False - - def notify(self, *args): - self.notified = True - - class MultiNotifierTestCase(test_utils.BaseTestCase): """Test case for notifications.""" @@ -282,35 +274,6 @@ class MultiNotifierTestCase(test_utils.BaseTestCase): self.assertEqual(self.exception_count, 2) self.assertEqual(self.notify_count, 1) - def test_adding_and_removing_notifier_object(self): - self.notifier_object = SimpleNotifier() - notification_driver = [ - 'openstack.common.notifier.no_op_notifier' - ] - self.config(notification_driver=notification_driver) - - notifier_api.add_driver(self.notifier_object) - notifier_api.notify(None, - 'publisher_id', - 'event_type', - notifier_api.WARN, - dict(a=3)) - self.assertEqual(self.notify_count, 1) - self.assertTrue(self.notifier_object.notified) - - self.notifier_object.notified = False - - def test_adding_and_removing_notifier_module(self): - self.config(notification_driver=[]) - - notifier_api.add_driver('openstack.common.notifier.no_op_notifier') - notifier_api.notify(None, - 'publisher_id', - 'event_type', - notifier_api.WARN, - dict(a=3)) - self.assertEqual(self.notify_count, 1) - def test_publisher_id(self): self.assertEqual(notifier_api.publisher_id('foobar'), 'foobar.' + socket.gethostname()) |
