예제 #1
0
파일: base.py 프로젝트: bopopescu/dashboard
def get_available_plugin_loaders():
    """Retrieve all the plugin classes available on the system.

    :returns: A dict with plugin entrypoint name as the key and the plugin
              loader as the value.
    :rtype: dict
    """
    mgr = stevedore.EnabledExtensionManager(namespace=PLUGIN_NAMESPACE,
                                            check_func=_auth_plugin_available,
                                            invoke_on_load=True,
                                            propagate_map_exceptions=True)

    return dict(mgr.map(lambda ext: (ext.entry_point.name, ext.obj)))
예제 #2
0
파일: base.py 프로젝트: bopopescu/dashboard
def get_available_plugin_names():
    """Get the names of all the plugins that are available on the system.

    This is particularly useful for help and error text to prompt a user for
    example what plugins they may specify.

    :returns: A list of names.
    :rtype: frozenset
    """
    mgr = stevedore.EnabledExtensionManager(namespace=PLUGIN_NAMESPACE,
                                            check_func=_auth_plugin_available,
                                            invoke_on_load=True,
                                            propagate_map_exceptions=True)
    return frozenset(mgr.names())
예제 #3
0
    def _load_plugins(self, test_block_config):
        """Load plugins from the 'tavern' entrypoint namespace

        This can be a module or a class as long as it defines the right things

        Todo:
            - Limit which plugins are loaded based on some config/command line
              option
            - Different plugin names

        Args:
            test_block_config (dict): available config for test

        Raises:
            exceptions.MissingSettingsError: Description

        Returns:
            list: Loaded plugins, can be a class or a module
        """
        # pylint: disable=no-self-use

        plugins = []

        for backend in ["http", "mqtt"]:
            namespace = "tavern_{}".format(backend)

            def enabled(ext):
                # pylint: disable=cell-var-from-loop
                return ext.name == test_block_config["backends"][backend]

            manager = stevedore.EnabledExtensionManager(
                namespace=namespace,
                check_func=enabled,
                verify_requirements=True,
                on_load_failure_callback=plugin_load_error,
            )
            manager.propagate_map_exceptions = True

            manager.map(is_valid_reqresp_plugin)

            if len(manager.extensions) != 1:
                raise exceptions.MissingSettingsError(
                    "Expected exactly one entrypoint in 'tavern-{}' namespace but got {}".format(
                        backend, len(manager.extensions)
                    )
                )

            plugins.extend(manager.extensions)

        return plugins