Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    def load_plugins(self):
        self.plugins = []

        for entrypoint in pkg_resources.iter_entry_points('%s.plugin' %
                                                          self._project_name):
            try:
                pluginclass = entrypoint.load()
                plugin = pluginclass(self._service_name)
                self.plugins.append(plugin)
            except Exception as exc:
                LOG.error(_("Failed to load plugin %(plug)s: %(exc)s") %
                          {'plug': entrypoint, 'exc': exc})

        # Register individual notifiers.
        for plugin in self.plugins:
            for notifier in plugin.notifiers:
                notifier_api.add_driver(notifier)
Ejemplo n.º 6
0
    def load_plugins(self):
        self.plugins = []

        for entrypoint in pkg_resources.iter_entry_points('%s.plugin' %
                                                          self._project_name):
            try:
                pluginclass = entrypoint.load()
                plugin = pluginclass(self._service_name)
                self.plugins.append(plugin)
            except Exception as exc:
                LOG.error(
                    _("Failed to load plugin %(plug)s: %(exc)s") % {
                        'plug': entrypoint,
                        'exc': exc
                    })

        # Register individual notifiers.
        for plugin in self.plugins:
            for notifier in plugin.notifiers:
                notifier_api.add_driver(notifier)
Ejemplo n.º 7
0
class PluginManager(object):
    """Manages plugin entrypoints and loading.

    For a service to implement this plugin interface for callback purposes:

      - Make use of the openstack-common notifier system
      - Instantiate this manager in each process (passing in
        project and service name)

    For an API service to extend itself using this plugin interface,
    it needs to query the plugin_extension_factory provided by
    the already-instantiated PluginManager.
    """
    def __init__(self, project_name, service_name):
        """ Construct Plugin Manager; load and initialize plugins.

        project_name (e.g. 'nova' or 'glance') is used
        to construct the entry point that identifies plugins.

        The service_name (e.g. 'compute') is passed on to
        each plugin as a raw string for it to do what it will.
        """
        self._project_name = project_name
        self._service_name = service_name
        self.plugins = []

    def load_plugins(self):
        self.plugins = []

        for entrypoint in pkg_resources.iter_entry_points('%s.plugin' %
                                                          self._project_name):
            try:
                pluginclass = entrypoint.load()
                plugin = pluginclass(self._service_name)
                self.plugins.append(plugin)
            except Exception, exc:
                LOG.error(
                    _("Failed to load plugin %(plug)s: %(exc)s") % {
                        'plug': entrypoint,
                        'exc': exc
                    })

        # Register individual notifiers.
        for plugin in self.plugins:
            for notifier in plugin.notifiers:
                notifier_api.add_driver(notifier)