Esempio n. 1
0
def test_prepare_request_for_build_binary_image_no_arch(
        mock_gia, mock_gri, mock_srs):
    mock_gia.side_effect = [{'amd64'}]

    expected = 'The binary image is not available for the following arches.+'
    with pytest.raises(IIBError, match=expected):
        utils.prepare_request_for_build(
            1,
            utils.RequestConfigAddRm(_binary_image='binary-image:latest',
                                     add_arches=['s390x']))
Esempio n. 2
0
def test_prepare_request_for_build_no_arches(mock_gia, mock_gri, mock_srs):
    mock_gia.side_effect = [{'amd64'}]

    with pytest.raises(IIBError, match='No arches.+'):
        utils.prepare_request_for_build(
            1, utils.RequestConfigAddRm(_binary_image='binary-image:latest'))
Esempio n. 3
0
def test_prepare_request_for_build(
    mock_ur,
    mock_gil,
    mock_gia,
    mock_gri,
    mock_srs,
    mock_srs2,
    add_arches,
    from_index,
    from_index_arches,
    bundles,
    binary_image,
    expected_bundle_mapping,
    distribution_scope,
    resolved_distribution_scope,
    binary_image_config,
):
    binary_image_resolved = 'binary-image@sha256:abcdef'
    from_index_resolved = None
    expected_arches = set(add_arches) | from_index_arches
    expected_payload_keys = {'binary_image_resolved', 'state', 'state_reason'}
    gil_side_effect = []
    ocp_version = 'v4.5'
    if expected_bundle_mapping:
        expected_payload_keys.add('bundle_mapping')
    if from_index:
        from_index_name = from_index.split(':', 1)[0]
        from_index_resolved = f'{from_index_name}@sha256:bcdefg'
        index_resolved = f'{from_index_name}@sha256:abcdef1234'
        mock_gri.side_effect = [
            from_index_resolved, binary_image_resolved, index_resolved
        ]
        mock_gia.side_effect = [from_index_arches, expected_arches]
        expected_payload_keys.add('from_index_resolved')
        gil_side_effect = ['v4.6', resolved_distribution_scope]
        ocp_version = 'v4.6'
    else:
        index_resolved = f'index-image@sha256:abcdef1234'
        mock_gri.side_effect = [binary_image_resolved, index_resolved]
        mock_gia.side_effect = [expected_arches]
        gil_side_effect = []

    if bundles:
        bundle_side_effects = [
            bundle.rsplit('/', 1)[1].split(':', 1)[0] for bundle in bundles
        ]
        gil_side_effect.extend(bundle_side_effects)

    mock_gil.side_effect = gil_side_effect

    rv = utils.prepare_request_for_build(
        1,
        utils.RequestConfigAddRm(
            _binary_image=binary_image,
            from_index=from_index,
            overwrite_from_index_token=None,
            add_arches=add_arches,
            bundles=bundles,
            distribution_scope=distribution_scope,
            binary_image_config=binary_image_config,
        ),
    )

    if not binary_image:
        binary_image = 'binary-image:prod'

    assert rv == {
        'arches': expected_arches,
        'binary_image': binary_image,
        'binary_image_resolved': binary_image_resolved,
        'bundle_mapping': expected_bundle_mapping,
        'from_index_resolved': from_index_resolved,
        'ocp_version': ocp_version,
        # want to verify that the output is always lower cased.
        'distribution_scope': resolved_distribution_scope.lower(),
        'source_from_index_resolved': None,
        'source_ocp_version': 'v4.5',
        'target_index_resolved': None,
        'target_ocp_version': 'v4.6',
    }