From 412ecf59c03b98c7cbb18ce9e1a24267c1f3d730 Mon Sep 17 00:00:00 2001 From: Andrew Bogott Date: Fri, 13 Jul 2012 18:52:11 -0500 Subject: 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 --- openstack/common/plugin/pluginmanager.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'openstack/common/plugin/pluginmanager.py') 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) -- cgit