Beispiel #1
0
 def verify(self, args):
     """Run the verify command
     """
     api.build_and_verify(source_dir=args.source_dir,
                          ui_validate_io=args.ui_validate_io,
                          validation_output=args.validation_output,
                          output=args.output)
Beispiel #2
0
def test_invalid_flat_bundles(nested_source_dir):
    with pytest.raises(OpCourierBadBundle) as err:
        api.build_and_verify(source_dir=nested_source_dir,
                             repository='oneagent')

    assert str(
        err.value
    ) == "Only 1 package is expected to exist in source root folder."
Beispiel #3
0
def test_make_bundle_invalid(yaml_files):
    yamls = []
    for file in yaml_files:
        with open(file, "r") as yaml_file:
            yamls.append(yaml_file.read())

    with pytest.raises(OpCourierBadBundle) as err:
        api.build_and_verify(yamls=yamls)

    assert str(err.value) == "Resulting bundle is invalid, " \
                             "input yaml is improperly defined."
Beispiel #4
0
def test_valid_zip_default_version(test_env, 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.clean_up_package(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': test_env['koji_builds']['valid_zip'],
        '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')

    quay_bundle = quay.get_bundle(test_env['test_namespace'],
                                  test_env['test_package'], '1.0.0')
    koji.download_manifest(nvr, tmp_path)
    koji_bundle = courier.build_and_verify(source_dir=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
Beispiel #5
0
def test_make_bundle_invalid(yaml_files):
    yamls = []
    for file in yaml_files:
        with open(file, "r") as yaml_file:
            yamls.append(yaml_file.read())

    with pytest.raises(OpCourierBadBundle) as e_info:
        api.build_and_verify(yamls=yamls)

    e = e_info.value
    e_msg = "Resulting bundle is invalid, input yaml is improperly defined."
    e_dict = {
        "warnings":
        ["csv metadata.annotations not defined.", "csv spec.icon not defined"],
        "errors": ["Bundle does not contain any packages."]
    }
    assert str(e) == e_msg
    assert e.validation_info == e_dict
def test_make_bundle(directory, expected):
    verified_manifest = api.build_and_verify(source_dir=directory)

    with open(expected, "r") as expected_file:
        expected_bundle = yaml.safe_load(expected_file)
    assert unformat_bundle(
        verified_manifest.bundle) == unformat_bundle(expected_bundle)
    assert not verified_manifest.nested
    assert hasattr(verified_manifest, 'bundle')
def test_invalid_nested_bundles(nested_source_dir):
    with pytest.raises(OpCourierBadBundle) as e_info:
        api.build_and_verify(source_dir=nested_source_dir,
                             repository='invalid_repo')

    e = e_info.value
    e_msg = "Resulting bundle is invalid, input yaml is improperly defined."
    expected_errors = {
        'csv apiVersion not defined.',
        'csv spec.installModes not defined',
        'The packageName (etcd) in bundle does not match repository name '
        '(invalid_repo) provided as command line argument.',
        'The packageName (etcd) in bundle does not match repository name '
        '(invalid_repo) provided as command line argument.',
        'The packageName (etcd) in bundle does not match repository name '
        '(invalid_repo) provided as command line argument.',
    }
    assert str(e) == e_msg
    assert set(e.validation_info['errors']) == expected_errors
Beispiel #8
0
def test_make_bundle_with_yaml_list(yaml_files, expected):
    yamls = []
    for file in yaml_files:
        with open(file, "r") as yaml_file:
            yamls.append(yaml_file.read())

    bundle = api.build_and_verify(yamls=yamls)

    with open(expected, "r") as expected_file:
        expected_bundle = yaml.safe_load(expected_file)
        assert unformat_bundle(bundle) == unformat_bundle(expected_bundle)
Beispiel #9
0
 def verify(self):
     parser = argparse.ArgumentParser(
         description='Build and verify an operator bundle to test')
     parser.add_argument('source_dir',
                         help='Path of your directory of yaml '
                         'files to bundle. Either set this or '
                         'use the files argument for bundle data.')
     parser.add_argument('--ui_validate_io',
                         help='Validate bundle for operatorhub.io UI. '
                         'To visually confirm that your operator '
                         'will be displayed correctly, please visit '
                         'https://operatorhub.io/preview and paste '
                         'your operator CSV.',
                         action='store_true')
     parser.add_argument(
         '--validation-output',
         dest='validation_output',
         help='A file to write validation warnings and errors to'
         'in JSON format')
     args, leftovers = parser.parse_known_args(sys.argv[2:])
     api.build_and_verify(source_dir=args.source_dir,
                          ui_validate_io=args.ui_validate_io,
                          validation_output=args.validation_output)
def test_make_bundle_with_yaml_list(yaml_files, expected):
    yamls = []
    for file in yaml_files:
        with open(file, "r") as yaml_file:
            yamls.append(yaml_file.read())

    verified_manifest = api.build_and_verify(yamls=yamls)

    with open(expected, "r") as expected_file:
        expected_bundle = yaml.safe_load(expected_file)
    assert unformat_bundle(
        verified_manifest.bundle) == unformat_bundle(expected_bundle)
    assert not verified_manifest.nested
    assert hasattr(verified_manifest, 'bundle')
def test_flatten_with_nvr(omps, quay, koji, tmp_path_factory):
    """
    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 = Bundle(quay.get_bundle(test_env['test_namespace'],
                                         test_env['test_package'], '1.0.0',
                                         authorization=None))

    koji_data = tmp_path_factory.mktemp('koji_data')
    flattened = tmp_path_factory.mktemp('flattened')
    koji.download_manifest(nvr, koji_data)
    courier.flatten(koji_data.as_posix(), flattened.as_posix())
    koji_bundle = Bundle(
        courier.build_and_verify(source_dir=flattened.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
Beispiel #12
0
def test_make_bundle(directory, expected):
    bundle = api.build_and_verify(source_dir=directory)

    with open(expected, "r") as expected_file:
        expected_bundle = yaml.safe_load(expected_file)
        assert unformat_bundle(bundle) == unformat_bundle(expected_bundle)
Beispiel #13
0
def test_invalid_nested_bundles(nested_source_dir):
    with pytest.raises(OpCourierBadBundle) as err:
        api.build_and_verify(source_dir=nested_source_dir, repository='etcd')

    assert str(err.value) == "Resulting bundle is invalid, " \
                             "input yaml is improperly defined."
Beispiel #14
0
def test_valid_nested_bundles(nested_source_dir):
    verified_manifest = api.build_and_verify(source_dir=nested_source_dir)
    assert verified_manifest.nested
    assert verified_manifest.is_valid