Exemple #1
0
def test_import_plugins_corrupted_registry(tmpdir_factory, description,
                                           registry_yaml):
    """
    Tests that it's not possible to import plugins with invalid registry file
    :param tmpdir_factory: pytest builtin fixture for creating temp dirs
    :param description: test description (adds a description in pytest run)
    :param registry_yaml: dictionary with data for registry file
    :return:
    """

    lp_dir = tmpdir_factory.mktemp('test_tmp_dir')
    lp_file = lp_dir.join('registry.yaml')

    with open(lp_file.strpath, 'w') as fp:
        yaml.dump(registry_yaml, fp, default_flow_style=True)

    try:
        with pytest.raises(IRValidatorException):
            RegistryValidator.validate_from_file(lp_file.strpath)
    finally:
        lp_dir.remove()
Exemple #2
0
def test_import_plugins_corrupted_registry(tmpdir_factory, description,
                                           registry_yaml):
    """
    Tests that it's not possible to import plugins with invalid registry file
    :param tmpdir_factory: pytest builtin fixture for creating temp dirs
    :param description: test description (adds a description in pytest run)
    :param registry_yaml: dictionary with data for registry file
    :return:
    """

    lp_dir = tmpdir_factory.mktemp('test_tmp_dir')
    lp_file = lp_dir.join('registry.yaml')

    with open(lp_file.strpath, 'w') as fp:
        yaml.dump(registry_yaml, fp, default_flow_style=True)

    try:
        with pytest.raises(IRValidatorException):
            RegistryValidator.validate_from_file(lp_file.strpath)
    finally:
        lp_dir.remove()
Exemple #3
0
    def import_plugins(self, plugins_registry):
        """
        Import and install plugins from registry yml file
        :param plugins_registry: Path/URL to plugin registry yml file
        """
        try:
            if not os.path.exists(plugins_registry):
                # if path was not found locally attempt to download it
                http = urllib3.PoolManager()
                urllib_ret = http.request('GET', plugins_registry)
                if urllib_ret.status is not 200:
                    # make sure we received OK status code from url
                    raise IRFailedToImportPlugins(
                        'Got unexpected returned code ({}) from registry '
                        'URL ({})'.format(urllib_ret.status, plugins_registry))
                # load registry from the url
                plugins_registry = \
                    RegistryValidator.validate_from_content(urllib_ret.data)
            else:
                # validate from local path
                plugins_registry = \
                    RegistryValidator.validate_from_file(plugins_registry)

        except urllib3.exceptions.HTTPError:
            raise IRFailedToImportPlugins(
                'Registry URL not found - ({}) '.format(plugins_registry))

        for plugin in set(plugins_registry):
            # if plugin exists remove it and then add from new registry
            if plugin in self.PLUGINS_DICT:
                self.remove_plugin(plugin)
                LOG.warning(
                    "Plugin '{}' has been successfully removed".format(plugin))
            # add the plugin
            self.add_plugin(plugin_source=plugin,
                            plugins_registry=plugins_registry)
            LOG.warning(
                "Plugin '{}' has been successfully installed".format(plugin))
Exemple #4
0
    def import_plugins(self, plugins_registry):
        """
        Import and install plugins from registry yml file
        :param plugins_registry: Path/URL to plugin registry yml file
        """
        try:
            if not os.path.exists(plugins_registry):
                # if path was not found locally attempt to download it
                http = urllib3.PoolManager()
                urllib_ret = http.request('GET', plugins_registry)
                if urllib_ret.status is not 200:
                    # make sure we received OK status code from url
                    raise IRFailedToImportPlugins(
                        'Got unexpected returned code ({}) from registry '
                        'URL ({})'.format(urllib_ret.status, plugins_registry))
                # load registry from the url
                plugins_registry = \
                    RegistryValidator.validate_from_content(urllib_ret.data)
            else:
                # validate from local path
                plugins_registry = \
                    RegistryValidator.validate_from_file(plugins_registry)

        except urllib3.exceptions.HTTPError:
            raise IRFailedToImportPlugins(
                'Registry URL not found - ({}) '.format(plugins_registry))

        for plugin in set(plugins_registry):
            # if plugin exists remove it and then add from new registry
            if plugin in self.PLUGINS_DICT:
                self.remove_plugin(plugin)
                LOG.warning(
                    "Plugin '{}' has been successfully removed".format(plugin))
            # add the plugin
            self.add_plugin(plugin_source=plugin,
                            plugins_registry=plugins_registry)
            LOG.warning(
                "Plugin '{}' has been successfully installed".format(plugin))