Beispiel #1
0
def test_nested_manifest(omps, quay, koji, tmp_path):
    """
    When the manifest data of an operator image has a nested structure,
    and the manifest data is pushed to Quay using the NVR endpoint,
    then pushing the data is successful.
    """
    version = '1.0.0'
    nvr = test_env['koji_builds']['nested_manifest']
    quay.delete(test_env['test_namespace'], test_env['test_package'])

    response = omps.fetch_nvr(organization=test_env['test_namespace'],
                              repo=test_env['test_package'],
                              nvr=nvr)

    assert response.status_code == requests.codes.ok
    assert response.json() == {
        'extracted_files': [
            '0.6.1/int-testcluster.crd.yaml',
            '0.6.1/int-testoperator.clusterserviceversion.yaml',
            '0.9.0/int-testbackup.crd.yaml', '0.9.0/int-testcluster.crd.yaml',
            '0.9.0/int-testoperator.v0.9.0.clusterserviceversion.yaml',
            '0.9.0/int-testrestore.crd.yaml', '0.9.2/int-testbackup.crd.yaml',
            '0.9.2/int-testoperator.v0.9.2.clusterserviceversion.yaml',
            'int-test.package.yaml'
        ],
        'nvr':
        nvr,
        'organization':
        test_env['test_namespace'],
        'repo':
        test_env['test_package'],
        'version':
        version,
    }
    assert quay.get_release(test_env['test_namespace'],
                            test_env['test_package'],
                            '1.0.0',
                            authorization=None)

    quay_bundle = make_bundle(
        quay.get_bundle(test_env['test_namespace'],
                        test_env['test_package'],
                        '1.0.0',
                        authorization=None))

    koji.download_manifest(nvr, tmp_path)
    koji_bundle = make_bundle(tmp_path.as_posix())

    # Note: this only confirms that OMPS used the right data from Koji,
    #       but tells nothing about the correctness of that data.
    assert quay_bundle == koji_bundle
def test_alter_package_name_during_archive_push(suffix_omps, suffix_quay, tmp_path):
    """
    When uploading an archive to a repository,
    and there is a configuration to alter package names for the namespace,
    then the package name is altered according to this configuration.
    """

    config = test_env["alter_package_name"]
    manifest_path = "tests/integration/artifacts/nested/"
    version = "1.0.0"
    suffix_quay.delete(config["namespace"], config["package"] + config["suffix"])

    assert not has(
        config["suffix"], manifest_path
    ), f"Found {config['suffix']} in the manifest at '{manifest_path}'"

    archive = shutil.make_archive(tmp_path / "archive", "zip", manifest_path)

    response = suffix_omps.upload(
        organization=config["namespace"], repo=config["package"], archive=archive,
    )

    assert response.status_code == requests.codes.ok

    quay_bundle = yaml.safe_load(
        make_bundle(
            suffix_quay.get_bundle(
                config["namespace"], config["package"] + config["suffix"], version,
            )
        )
    )
    assert quay_bundle["packageName"] == config["package"] + config["suffix"]

    check_csv_annotations(quay_bundle, config["csv_annotations"])
def test_alter_package_name_during_nvr_push(suffix_omps, suffix_quay, koji, tmp_path):
    """
    When the manifest data is pushed to Quay using the NVR endpoint,
    and there is a configuration to alter package names for the namespace,
    then the package name is altered according to this configuration.
    """
    config = test_env["alter_package_name"]
    version = "1.0.0"
    nvr = test_env["koji_builds"]["alter_package_name"]
    suffix_quay.delete(config["namespace"], config["package"] + config["suffix"])

    # check that packageName in the manifest is without the suffix
    koji.download_manifest(nvr, tmp_path)

    assert not has(
        config["suffix"], tmp_path
    ), f"Found {config['suffix']} in the manifest of '{nvr}'"

    response = suffix_omps.fetch_nvr(
        organization=config["namespace"], repo=config["package"], nvr=nvr
    )
    response.raise_for_status()

    quay_bundle = yaml.safe_load(
        make_bundle(
            suffix_quay.get_bundle(
                config["namespace"], config["package"] + config["suffix"], version,
            )
        )
    )

    assert quay_bundle["packageName"] == config["package"] + config["suffix"]

    check_csv_annotations(quay_bundle, config["csv_annotations"])
Beispiel #4
0
def test_valid_zip_default_version(omps, quay, koji, tmp_path):
    """
    When fetching an NVR from Koji,
    and it's going to be the first release in the package,
    and there is no version specified,
    then the release gets the default version number,
    and the bundle uploaded to Quay is the same as the one generated
        from the Koji archive.
    """
    nvr = test_env['koji_builds']['valid_zip']
    quay.delete(test_env['test_namespace'], test_env['test_package'])

    response = omps.fetch_nvr(organization=test_env['test_namespace'],
                              repo=test_env['test_package'],
                              nvr=nvr)

    assert response.status_code == requests.codes.ok
    assert response.json() == {
        'extracted_files': ['crd.yaml', 'csv.yaml', 'packages.yaml'],
        'nvr': nvr,
        'organization': test_env['test_namespace'],
        'repo': test_env['test_package'],
        'version': '1.0.0',
    }
    assert quay.get_release(test_env['test_namespace'],
                            test_env['test_package'],
                            '1.0.0',
                            authorization=None)

    quay_bundle = make_bundle(
        quay.get_bundle(test_env['test_namespace'],
                        test_env['test_package'],
                        '1.0.0',
                        authorization=None))
    koji.download_manifest(nvr, tmp_path)
    koji_bundle = make_bundle(
        courier.build_and_verify(source_dir=tmp_path.as_posix()).bundle)

    # Note: this only confirms that OMPS used the right data from Koji,
    #       but tells nothing about the correctness of that data.
    assert quay_bundle == koji_bundle
def test_replace_during_archive_push(omps, quay, tmp_path_factory,
                                     manifest_path):
    """
    When uploading an archive to a repository,
    and there is a configuration to replace registries,
    then the bundle in Quay has the registries replaces accordingly.
    """

    version = "1.0.0"
    # Make sure there test_env['test_package'] operator is empty.
    releases = [
        r["release"] for r in quay.get_releases(test_env["test_namespace"],
                                                test_env["test_package"])
    ]
    quay.delete_releases(
        "/".join([test_env["test_namespace"], test_env["test_package"]]),
        releases)

    # Use the registries which are expected to be replaced.
    artifacts_dir = tmp_path_factory.mktemp("artifacts")
    dir_util.copy_tree(manifest_path, artifacts_dir.as_posix())
    replace_conf = cycle(test_env["replace_registry"])
    for dirpath, dirnames, filenames in os.walk(artifacts_dir):
        for filename in filter(is_yaml_file, filenames):
            path = os.path.join(dirpath, filename)
            with open(path, "r") as fp:
                content = fp.read()
            content_changed = False

            # In order to make sure that all the elements from the
            # configuration list are used, cycle through the list of
            # configuration while replacing the placeholder.
            #
            # This is also required for the check at the end of the test to
            # work when there are multiple replacements configured.
            while r"{REGISTRY}" in content:
                content = content.replace(r"{REGISTRY}",
                                          next(replace_conf)["old"], 1)
                content_changed = True

            if content_changed:
                with open(path, "w") as fp:
                    fp.write(content)

    archive_dir = tmp_path_factory.mktemp("archive")
    archive = shutil.make_archive(archive_dir / "archive", "zip",
                                  artifacts_dir)
    response = omps.upload(
        organization=test_env["test_namespace"],
        repo=test_env["test_package"],
        archive=archive,
    )
    response.raise_for_status()

    quay_bundle = make_bundle(
        quay.get_bundle(
            test_env["test_namespace"],
            test_env["test_package"],
            version,
            authorization=None,
        ))

    for config in test_env["replace_registry"]:
        assert config["old"] not in quay_bundle
        assert config["new"] in quay_bundle
def test_replace_during_nvr_push(omps, quay, koji, tmp_path):
    """
    When the manifest data of an operator image has a nested structure,
    and the manifest data is pushed to Quay using the NVR endpoint,
    and there is a configuration to replace registries,
    then the bundle in Quay has the registries replaces accordingly.
    """
    version = "1.0.0"
    nvr = test_env["koji_builds"]["replace_registry"]
    quay.delete(test_env["test_namespace"], test_env["test_package"])

    koji.download_manifest(nvr, tmp_path)

    def koji_registries(replace_conf, path):
        """
        Find which 'old' registries from 'replace_conf' can be found in
        the manifest at 'path'

        Args:
            replace_conf: List of {'old': ..., 'new': ...} dictionaries.
            path: Path of the manifest.

        Returns:
            List of registries (strings) which were found in the manifest at 'path'.
        """
        content = ""
        for dirpath, dirnames, filenames in os.walk(path):
            for filename in filter(is_yaml_file, filenames):
                path = os.path.join(dirpath, filename)
                with open(path, "r") as fp:
                    content += fp.read()

        found = []
        for conf in replace_conf:
            if conf["old"] in content:
                found.append(conf)

        return found

    registries_to_replace = koji_registries(test_env["replace_registry"],
                                            tmp_path)
    assert registries_to_replace, (
        f"The 'replace_registry' test configuration should have at least one of the "
        f"'old' registries present in the manifest of '{nvr}'")

    response = omps.fetch_nvr(organization=test_env["test_namespace"],
                              repo=test_env["test_package"],
                              nvr=nvr)
    response.raise_for_status()

    quay_bundle = make_bundle(
        quay.get_bundle(
            test_env["test_namespace"],
            test_env["test_package"],
            version,
            authorization=None,
        ))

    for config in registries_to_replace:
        assert config["old"] not in quay_bundle
        assert config["new"] in quay_bundle