import shutil import pytest from distutils import dir_util from itertools import cycle from tests.integration.utils import test_env, Bundle def is_yaml_file(path): """ Tell if 'path' ends in .yaml or .yml """ return path.endswith(".yaml") or path.endswith(".yml") @pytest.mark.skipif( not test_env.get("replace_registry"), reason="No configuration to replace registries.", ) 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)
suffix: Suffix string that is looked for. manifest_path: Path of the manifest. Returns: True, if 'suffix' was found, False otherwise. """ for filename in filter(is_yaml_file, os.listdir(manifest_path)): path = os.path.join(manifest_path, filename) with open(path, "r") as fp: if suffix in fp.read(): return True return False @pytest.mark.skipif( not test_env.get("alter_package_name"), reason="No configuration to test altering package names", ) 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 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': next_version, } assert quay.get_release(test_env['test_namespace'], test_env['test_package'], next_version, authorization=None) @pytest.mark.skipif(not test_env.get("greenwave"), reason="Greenwave is not configured") @pytest.mark.parametrize("build,policies_satisfied,summary", [ ("greenwave_passed", True, "no tests are required"), ("greenwave_failed", False, "1 of 1 required test results missing"), ], ids=["passed", "failed"]) def test_greenwave(omps, quay, tmp_path, build, policies_satisfied, summary): """ When fetching an NVR from Koji, and Greenwave is configured, then the push succeeds or fails depending on the Greenwave policies being satisfied or not. """ nvr = test_env["koji_builds"][build] version = "1.0.0"
def test_upload_invalid_artifact(omps, tmp_path): """ Push fails, if the artifact does not pass quay-courier validation. """ archive = shutil.make_archive(tmp_path / 'archive', 'zip', 'tests/integration/artifacts/invalid/') response = omps.upload(organization=test_env['test_namespace'], repo=test_env['test_package'], archive=archive) assert response.status_code == requests.codes.bad_request assert response.json()['error'] == 'PackageValidationError' assert 'bundle is invalid' in response.json()['message'] @pytest.mark.skipif(not test_env.get('private_org'), reason='No private organization configured.') def test_private_organization(private_omps, private_quay, tmp_path_factory): """ When packages are pushed to an organization, which is not configured to hold public packages, Then a newly created package is private. """ namespace = test_env['private_org']['namespace'] package = test_env['private_org']['package'] version = '1.0.0' private_quay.delete(namespace, package) # Make sure artifact's packageName matches package name used for the push. artifacts_dir = tmp_path_factory.mktemp('artifacts') dir_util.copy_tree('tests/integration/artifacts/valid/',
'extracted_files': [ 'crd.yaml', 'csv.yaml', 'packages.yaml' ], 'nvr': nvr, 'organization': test_env['test_namespace'], 'repo': test_env['test_package'], 'version': next_version, } assert quay.get_release(test_env['test_namespace'], test_env['test_package'], next_version, authorization=None) @pytest.mark.skipif(not test_env.get("greenwave"), reason="Greenwave is not configured") @pytest.mark.parametrize( "build,policies_satisfied,summary", [ ("greenwave_passed", True, "no tests are required"), ("greenwave_failed", False, "1 of 1 required test results missing"), ], ids=["passed", "failed"] ) def test_greenwave(omps, quay, tmp_path, build, policies_satisfied, summary): """ When fetching an NVR from Koji, and Greenwave is configured, then the push succeeds or fails depending on the Greenwave policies being satisfied or not. """