def plugin_already_uploaded(wagon_path):
    """
    Check if a plugin is already loaded on the manager.
    :param wagon_path: Path to a wagon.
    :return: Bool.
    """

    # It`s url
    if '://' in wagon_path:
        wagon_metadata = show(wagon_path)
    else:
        wagon_metadata = show(find_wagon_local_path(wagon_path))
    plugin_name = wagon_metadata["package_name"]
    plugin_version = wagon_metadata["package_version"]
    plugin_distribution = \
        wagon_metadata["build_server_os_properties"]["distribution"]
    for plugin in cloudify_exec('cfy plugins list'):
        logger.info('CHECKING if {0} {1} {2} in {3}'.format(
            plugin_name, plugin_version, plugin_distribution, plugin))
        compare_name = plugin['package_name']
        compare_version = plugin['package_version']
        compare_distro = plugin.get('distribution', '').lower() or plugin.get(
            'yaml_url_path', '')

        if plugin_name.replace('_', '-') in compare_name and \
                plugin_version == compare_version and \
                plugin_distribution.lower() in compare_distro:
            return True
예제 #2
0
    def install(self, source):
        """
        Install a wagon plugin.
        """
        metadata = wagon.show(source)
        cls = self._model.plugin.model_cls

        os_props = metadata['build_server_os_properties']

        plugin = cls(
            name=metadata['package_name'],
            archive_name=metadata['archive_name'],
            supported_platform=metadata['supported_platform'],
            supported_py_versions=metadata['supported_python_versions'],
            distribution=os_props.get('distribution'),
            distribution_release=os_props['distribution_version'],
            distribution_version=os_props['distribution_release'],
            package_name=metadata['package_name'],
            package_version=metadata['package_version'],
            package_source=metadata['package_source'],
            wheels=metadata['wheels'],
            uploaded_at=datetime.now())
        if len(
                self._model.plugin.list(
                    filters={
                        'package_name': plugin.package_name,
                        'package_version': plugin.package_version
                    })):
            raise exceptions.PluginAlreadyExistsError(
                'Plugin {0}, version {1} already exists'.format(
                    plugin.package_name, plugin.package_version))
        self._install_wagon(source=source, prefix=self.get_plugin_dir(plugin))
        self._model.plugin.put(plugin)
        return plugin
예제 #3
0
    def _load_plugin_package_json(wagon_source):
        if wagon.validate(wagon_source):
            # wagon returns a list of validation issues.
            raise manager_exceptions.InvalidPluginError(
                'the provided wagon can not be read.')

        return wagon.show(wagon_source)
예제 #4
0
    def _load_plugin_package_json(wagon_source):
        # Disable validation for now - seems to break in certain
        # circumstances.
        # if wagon.validate(wagon_source):
        #     # wagon returns a list of validation issues.
        #     raise manager_exceptions.InvalidPluginError(
        #         'the provided wagon can not be read.')

        return wagon.show(wagon_source)
예제 #5
0
    def test_create_with_requirements(self):
        test_package = os.path.join('tests', 'resources', 'test-package')
        requirement_files = [os.path.join(test_package, 'requirements.txt')]

        archive_path = wagon.create(source=test_package,
                                    force=True,
                                    requirement_files=requirement_files)
        self.archive_name = os.path.basename(archive_path)
        self.platform = 'any'
        metadata = wagon.show(self.archive_name)
        wheel_names = [whl.split('-')[0] for whl in metadata['wheels']]
        assert 'wheel' in wheel_names
        assert 'test_package' in wheel_names
예제 #6
0
    def _load_plugin_package_json(wagon_source):
        # Disable validation for now - seems to break in certain
        # circumstances.
        # if wagon.validate(wagon_source):
        #     # wagon returns a list of validation issues.
        #     raise manager_exceptions.InvalidPluginError(
        #         'the provided wagon can not be read.')

        try:
            return wagon.show(wagon_source)
        except wagon.WagonError as e:
            raise manager_exceptions.InvalidPluginError(
                'The provided wagon archive can not be read.\n{0}'.format(
                    e.message))
    def _load_plugin_package_json(wagon_source):
        # Disable validation for now - seems to break in certain
        # circumstances.
        # if wagon.validate(wagon_source):
        #     # wagon returns a list of validation issues.
        #     raise manager_exceptions.InvalidPluginError(
        #         'the provided wagon can not be read.')

        try:
            return wagon.show(wagon_source)
        except wagon.WagonError as e:
            raise manager_exceptions.InvalidPluginError(
                'The provided wagon archive can not be read.\n{0}'
                .format(e.message))
예제 #8
0
def build_plugins_bundle_with_workspace(workspace_path=None, v2_bundle=False):
    """
    Get wagons and md5 files from the workspace and replace the old values in
    plugins.json with the new values. This is only used to build the
    bundle, it's not what's published.
    :return:
    """
    plugins_json = {}
    # Get all the workspace files
    files = [
        f for f in get_workspace_files(workspace_path=workspace_path)
        if f.endswith('wgn') or f.endswith('md5')
    ]
    files = list(set(files))
    files.sort()
    logging.info('build_plugins_bundle_with_workspace Files: {}'.format(files))
    for i in range(0, len(files), 2):
        if files[i].endswith('.wgn'):
            plugin = (files[i], files[i + 1])
            wagon_metadata = show(find_wagon_local_path(plugin[0]))
            logging.info(
                'Build plugins bundle {md}.'.format(md=wagon_metadata))
            plugin_name = wagon_metadata["package_name"]
            plugin_version = wagon_metadata["package_version"]
            plugins_json = get_plugin_new_json(PLUGINS_JSON_PATH, plugin_name,
                                               plugin_version, plugin,
                                               plugins_json, v2_bundle)
            logging.info('Build plugins json {i} {out}'.format(
                i=i, out=plugins_json))
        else:
            try:
                os.remove(files[i])
            except OSError:
                raise Exception(
                    'Illegal files list {files}'.format(files=files[i]))
    copy_plugins_json_to_workspace(write_json(plugins_json))
    bundle_path = build_plugins_bundle(plugins_json, v2_bundle)
    workspace_path = os.path.join(os.path.abspath('workspace'), 'build',
                                  os.path.basename(bundle_path))

    shutil.copyfile(bundle_path, workspace_path)
    logging.info('build_plugins_bundle_with_workspace fn report_tar_contents.')
    report_tar_contents(workspace_path)
예제 #9
0
 def test_create_archive_in_destination_dir_from_pypi_latest(self):
     temp_dir = tempfile.mkdtemp()
     shutil.rmtree(temp_dir, ignore_errors=True)
     package = 'wheel'
     try:
         pypi_version = \
             wagon._get_package_info_from_pypi(package)['version']
         self.archive_name = \
             wagon._set_archive_name(
                 package,
                 pypi_version,
                 self.python_versions,
                 'any')
         result = _wagon(['create', package, '-v', '-f', '-o', temp_dir])
         assert result.returncode == 0
         metadata = wagon.show(os.path.join(temp_dir, self.archive_name))
         assert pypi_version == metadata['package_version']
     finally:
         shutil.rmtree(temp_dir, ignore_errors=True)
예제 #10
0
 def test_create_archive_in_destination_dir_from_pypi_latest(self):
     temp_dir = tempfile.mkdtemp()
     shutil.rmtree(temp_dir, ignore_errors=True)
     package = 'wheel'
     try:
         self.platform = 'any'
         pypi_version = \
             wagon._get_package_info_from_pypi(package)['version']
         self.archive_name = \
             wagon._set_archive_name(
                 package,
                 pypi_version,
                 self.python_versions,
                 self.platform)
         result = _invoke('wagon create {0} -v -f -o {1}'.format(
             package, temp_dir))
         assert result.returncode == 0
         metadata = wagon.show(os.path.join(temp_dir, self.archive_name))
         self.platform = 'linux_x86_64'
         assert pypi_version == metadata['package_version']
     finally:
         shutil.rmtree(temp_dir, ignore_errors=True)