diff options
| author | Andrew Bogott <abogott@wikimedia.org> | 2012-07-13 18:52:11 -0500 |
|---|---|---|
| committer | Andrew Bogott <abogott@wikimedia.org> | 2012-07-15 16:09:18 -0500 |
| commit | 412ecf59c03b98c7cbb18ce9e1a24267c1f3d730 (patch) | |
| tree | c1c34cd0f6d7f81c9a9793dbaff0cb61731c147f | |
| parent | ce3071437d1871f77c4d8573cbe5f4ea8c817650 (diff) | |
| download | oslo-412ecf59c03b98c7cbb18ce9e1a24267c1f3d730.tar.gz oslo-412ecf59c03b98c7cbb18ce9e1a24267c1f3d730.tar.xz oslo-412ecf59c03b98c7cbb18ce9e1a24267c1f3d730.zip | |
Don't switch to list_notifier unless necessary.
Some notification tests depend on a different, single notifier being
used. So, don't switch to the list notifier just because we loaded
this class; only switch if an actual plugin needs it.
Also: improved the test that makes sure all this notifier-switching
doesn't break the notifier that was present in the first place.
Change-Id: I170477bccb3ad9505fe6dbfbc214f77c09f6862f
| -rw-r--r-- | openstack/common/plugin/pluginmanager.py | 26 | ||||
| -rw-r--r-- | tests/unit/test_plugin.py | 24 |
2 files changed, 33 insertions, 17 deletions
diff --git a/openstack/common/plugin/pluginmanager.py b/openstack/common/plugin/pluginmanager.py index 2e3d497..d9b6bc3 100644 --- a/openstack/common/plugin/pluginmanager.py +++ b/openstack/common/plugin/pluginmanager.py @@ -53,15 +53,16 @@ class PluginManager(object): self._service_name = service_name self.plugins = [] - # Make sure we're using the list_notifier. - if not hasattr(CONF, "list_notifier_drivers"): - CONF.list_notifier_drivers = [] - old_notifier = CONF.notification_driver - drvstring = 'openstack.common.notifier.list_notifier' - CONF.notification_driver = drvstring - if (old_notifier and - old_notifier != 'openstack.common.notifier.list_notifier'): - list_notifier.add_driver(old_notifier) + def _force_use_list_notifier(self): + if (CONF.notification_driver != + 'openstack.common.notifier.list_notifier'): + if not hasattr(CONF, "list_notifier_drivers"): + CONF.list_notifier_drivers = [] + old_notifier = CONF.notification_driver + drvstring = 'openstack.common.notifier.list_notifier' + CONF.notification_driver = drvstring + if old_notifier: + list_notifier.add_driver(old_notifier) def load_plugins(self): self.plugins = [] @@ -76,6 +77,13 @@ class PluginManager(object): LOG.error(_("Failed to load plugin %(plug)s: %(exc)s") % {'plug': entrypoint, 'exc': exc}) + # See if we need to turn on the list notifier + for plugin in self.plugins: + if plugin.notifiers: + self._force_use_list_notifier() + break + + # Register individual notifiers. for plugin in self.plugins: for notifier in plugin.notifiers: list_notifier.add_driver(notifier) diff --git a/tests/unit/test_plugin.py b/tests/unit/test_plugin.py index cfbbb23..01665ba 100644 --- a/tests/unit/test_plugin.py +++ b/tests/unit/test_plugin.py @@ -16,6 +16,7 @@ import pkg_resources import unittest +from openstack.common import cfg from openstack.common import notifier from openstack.common.notifier import api as notifier_api from openstack.common.notifier import no_op_notifier @@ -33,6 +34,12 @@ class SimpleNotifier(object): self.message_list.append(message) +class SimplerNotifier(object): + def notify(self, context, message): + global simpler_notify_called + simpler_notify_called = True + + class ManagerTestCase(test_utils.BaseTestCase): def tearDown(self): super(ManagerTestCase, self).tearDown() @@ -49,13 +56,10 @@ class NotifyTestCase(test_utils.BaseTestCase): # Set up a 'normal' notifier to make sure the plugin logic # doesn't mess anything up. - self.config( - notification_driver='openstack.common.notifier.no_op_notifier') - - def mock_notify(cls, *args): - self.no_op_notify_called = True - self.stubs.Set(no_op_notifier, 'notify', - mock_notify) + self.stubs.Set(cfg.CONF, 'notification_driver', + SimplerNotifier()) + global simpler_notify_called + simpler_notify_called = False def tearDown(self): super(NotifyTestCase, self).tearDown() @@ -90,7 +94,11 @@ class NotifyTestCase(test_utils.BaseTestCase): notifier_api.WARN, dict(a=3)) self.assertEqual(len(notifier.message_list), 1) - self.assertTrue(self.no_op_notify_called) + + # Verify that the original baseline notifier is still + # installed and working. + global simpler_notify_called + self.assertTrue(simpler_notify_called) class StubControllerExtension(object): |
