예제 #1
0
def strategy_runner(package, run_type, remote=False, **kwargs):
    """Run the packaging functions

        Args:
            package (dict): package_config
            run_type (str): Represent the strategy to run on a package (test or artifact)
            remote (bool): Represent if the plugin is executed in remote or not, default value: False

        Raises:
            CITestFail: some error occurred during the test
            CITestUnknown: wrong value for config['test_type']
            CIBuildPackageFail: some error occurred during a packaging
            ImportPluginError: Fail to find / import a plugin
    """

    logger = Log()

    if run_type in ["test", "artifact"]:

        if run_type == "test" and package["test_type"] == "no-test":
            logger.info("Tag no-test detected, skip test")
            return {}

        params = {"type": "test_type", "exception": CITestFail}\
            if run_type == "test" else {"type": "artifact_type", "exception": CIBuildPackageFail}

        try:
            plugin = find_plugin(package[params["type"]],
                                 run_type,
                                 PLUGINS_INFO["locations"],
                                 PLUGINS_INFO["workspace"])
            logger.info("The plugin {} is loaded".format(package[params["type"]]))
        except ImportPluginError:
            raise

        logger.info("Starting {} plugin ...".format(package[params["type"]]))
        try:
            return plugin.run(package, remote)
        except Exception as e:
            logger.error(str(e))
            raise params["exception"](str(e))

    elif run_type == "dependency":
        dependencies = set(package.get("depends_on", []))

        for plugin_type in package["dependencies_type"]:
            try:
                plugin = find_plugin(plugin_type,
                                     run_type,
                                     PLUGINS_INFO["locations"],
                                     PLUGINS_INFO["workspace"])
                logger.info("The plugin {} is loaded".format(plugin_type))
            except ImportPluginError:
                raise

            dependencies |= plugin.Plugin(kwargs.get("basepath"))

        return dependencies
    else:
        raise ValueError("run_type must be equal to {}, actual value: {}".format(", ".join(ACCEPT_RUN_TYPE), run_type))
예제 #2
0
def test_find_plugin_failed_on_all_import(mocker, plugin_type):
    def fake_import(*args, **kwargs):
        raise ImportError

    mocker.patch("loktar.plugin.importlib.import_module", side_effect=fake_import)
    with pytest.raises(ImportPluginError):
        find_plugin("foo", plugin_type, ["/tmp/bar", "/toto/tutu"], "toto")
예제 #3
0
def test_find_plugin_failed_on_first_import_but_find_a_plugin_in_plugin_path(mocker, plugin_type):
    def fake_import(*args, **kwargs):
        if "loktar" in args[0]:
            raise ImportError

    mocker.patch("loktar.plugin.importlib.import_module", side_effect=fake_import)
    find_plugin("foo", plugin_type, ["/tmp/bar", "/toto/tutu"], "toto")
예제 #4
0
def test_find_plugin(mocker, plugin_type):
    mocker.patch("loktar.plugin.importlib")
    find_plugin("foo", plugin_type, ["/tmp/bar", "/toto/tutu"], "toto")