예제 #1
0
def test_scan_invalid_file_csv(monkeypatch, line):
    monkeypatch.setattr(api, 'current_actor',
                        CurrentActorMocked(architecture.ARCH_X86_64))
    monkeypatch.setattr(api, 'produce', produce_mocked())
    with pytest.raises(StopActorExecutionError) as err:
        repositoriesmapping.scan_repositories(
            read_repofile_func=ReadRepoFileMock([line]))
    assert not api.produce.called
    assert 'The repository mapping file is invalid' in str(err)
예제 #2
0
def test_scan_missing_or_empty_file(monkeypatch, isFile, err_summary):
    monkeypatch.setattr(api, 'current_actor',
                        CurrentActorMocked(architecture.ARCH_X86_64))
    monkeypatch.setattr(api, 'produce', produce_mocked())
    monkeypatch.setattr('os.path.isfile', lambda dummy: isFile)
    if isFile:
        monkeypatch.setattr('os.path.getsize', lambda dummy: 0)
    with pytest.raises(StopActorExecutionError) as err:
        repositoriesmapping.scan_repositories()
    assert not api.produce.called
    assert err_summary in str(err)
예제 #3
0
def test_scan_repositories_with_missing_data(monkeypatch):
    """
    Tests whether the scanning process fails gracefully when no data are read.
    """
    monkeypatch.setattr(api, 'current_actor',
                        CurrentActorMocked(src_ver='7.9', dst_ver='8.4'))
    monkeypatch.setattr(api, 'produce', produce_mocked())
    monkeypatch.setattr(repositoriesmapping, 'read_or_fetch', lambda dummy: '')

    with pytest.raises(StopActorExecutionError) as missing_data_error:
        repositoriesmapping.scan_repositories()
    assert 'does not contain a valid JSON object' in str(missing_data_error)
예제 #4
0
def test_scan_repositories_with_empty_data(monkeypatch):
    """
    Tests whether the scanning process fails gracefully when empty json data received.
    """

    monkeypatch.setattr(api, 'current_actor',
                        CurrentActorMocked(src_ver='7.9', dst_ver='8.4'))
    monkeypatch.setattr(api, 'produce', produce_mocked())

    with pytest.raises(StopActorExecutionError) as empty_data_error:
        repositoriesmapping.scan_repositories(lambda dummy: {})
    assert 'the JSON is missing a required field' in str(empty_data_error)
예제 #5
0
def test_scan_missing_or_empty_file(monkeypatch, isFile):
    monkeypatch.setattr(api, 'current_actor',
                        CurrentActorMocked(architecture.ARCH_X86_64))
    monkeypatch.setattr(api, 'produce', produce_mocked())
    monkeypatch.setattr('os.path.isfile', lambda dummy: False)
    monkeypatch.setattr(requests, 'get', get_mocked(200 if isFile else 404,
                                                    ''))

    with pytest.raises(StopActorExecutionError) as err:
        repositoriesmapping.scan_repositories()
    assert not api.produce.called
    assert 'invalid or could not be retrieved' in str(err)
예제 #6
0
def test_scan_repositories_with_repo_entry_mapping_target_not_a_list(
        monkeypatch):
    """
    Tests whether deserialization of a mapping entry that has its target field set to a string
    is handled internally and StopActorExecutionError is propagated to the user.
    """

    json_data = {
        'datetime':
        '202107141655Z',
        'version_format':
        repositoriesmapping.RepoMapData.VERSION_FORMAT,
        'mapping': [{
            'source_major_version':
            '7',
            'target_major_version':
            '8',
            'entries': [{
                'source': 'source_pesid',
                'target': 'target_pesid'
            }]
        }],
        'repositories': [{
            'pesid':
            'source_pesid',
            'entries': [{
                'major_version': '7',
                'repoid': 'some-rhel-9-repo1',
                'arch': 'x86_64',
            }]
        }, {
            'pesid':
            'target_pesid',
            'entries': [{
                'major_version': '7',
                'repoid': 'some-rhel-9-repo1',
                'arch': 'x86_64',
            }]
        }]
    }

    monkeypatch.setattr(api, 'current_actor',
                        CurrentActorMocked(src_ver='7.9', dst_ver='8.4'))
    monkeypatch.setattr(api, 'produce', produce_mocked())

    with pytest.raises(StopActorExecutionError) as error_info:
        repositoriesmapping.scan_repositories(lambda dummy: json_data)

    assert 'repository mapping file is invalid' in error_info.value.message
예제 #7
0
def test_scan_valid_file_without_comments(monkeypatch, arch, src_type,
                                          dst_type):
    envars = {
        'LEAPP_DEVEL_SOURCE_PRODUCT_TYPE': src_type,
        'LEAPP_DEVEL_TARGET_PRODUCT_TYPE': dst_type
    }
    input_data, expected_records = gen_test_data(arch, src_type, dst_type)
    monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(arch, envars))
    monkeypatch.setattr(api, 'produce', produce_mocked())
    repositoriesmapping.scan_repositories(
        read_repofile_func=ReadRepoFileMock(input_data))
    assert api.produce.called == 1
    assert api.produce.model_instances == [
        gen_RepositoriesMap(expected_records)
    ]
예제 #8
0
def test_scan_repositories_with_mapping_to_pesid_without_repos(monkeypatch):
    """
    Tests that the loading of repositories mapping recognizes when there is a mapping with target pesid that does
    not have any repositories and inhibits the upgrade.
    """
    json_data = {
        'datetime':
        '202107141655Z',
        'version_format':
        repositoriesmapping.RepoMapData.VERSION_FORMAT,
        'mapping': [{
            'source_major_version':
            '7',
            'target_major_version':
            '8',
            'entries': [{
                'source': 'source_pesid',
                'target': ['nonexisting_pesid']
            }]
        }],
        'repositories': [{
            'pesid':
            'source_pesid',
            'entries': [{
                'major_version': '7',
                'repoid': 'some-rhel-7-repo',
                'arch': 'x86_64',
                'repo_type': 'rpm',
                'channel': 'eus'
            }]
        }]
    }

    monkeypatch.setattr(api, 'current_actor',
                        CurrentActorMocked(src_ver='7.9', dst_ver='8.4'))
    monkeypatch.setattr(api, 'produce', produce_mocked())

    with pytest.raises(StopActorExecutionError) as error_info:
        repositoriesmapping.scan_repositories(lambda dummy: json_data)

    assert 'pesid is not related to any repository' in error_info.value.message
예제 #9
0
def test_scan_repositories_with_bad_json_data_version(monkeypatch,
                                                      version_format):
    """
    Tests whether the json data is checked for the version field and error is raised if the version
    does not match the latest one.
    """

    json_data = {
        'datetime': '202107141655Z',
        'version_format': version_format,
        'mapping': [],
        'repositories': []
    }

    monkeypatch.setattr(api, 'current_actor',
                        CurrentActorMocked(src_ver='7.9', dst_ver='8.4'))
    monkeypatch.setattr(api, 'produce', produce_mocked())

    with pytest.raises(StopActorExecutionError) as bad_version_error:
        repositoriesmapping.scan_repositories(lambda dummy: json_data)

    assert 'mapping file is invalid' in str(bad_version_error)
예제 #10
0
def test_scan_existing_valid_data(monkeypatch, adjust_cwd):
    """
    Tests whether an existing valid repomap file is loaded correctly.
    """

    with open('files/repomap_example.json') as repomap_file:
        data = json.load(repomap_file)
    monkeypatch.setattr(api, 'current_actor',
                        CurrentActorMocked(src_ver='7.9', dst_ver='8.4'))
    monkeypatch.setattr(api, 'produce', produce_mocked())

    repositoriesmapping.scan_repositories(lambda dummy: data)

    assert api.produce.called, 'Actor did not produce any message when deserializing valid repomap data.'

    fail_description = 'Actor produced multiple messages, but only one was expected.'
    assert len(api.produce.model_instances) == 1, fail_description

    repo_mapping = api.produce.model_instances[0]

    # Verify that the loaded JSON data is matching the repomap file content
    # 1. Verify src_pesid -> target_pesids mappings are loaded and filtered correctly
    fail_description = 'Actor produced more mappings than there are source system relevant mappings in the test file.'
    assert len(repo_mapping.mapping) == 1, fail_description
    fail_description = 'Actor failed to load IPU-relevant mapping data correctly.'
    assert repo_mapping.mapping[0].source == 'pesid1', fail_description
    assert set(repo_mapping.mapping[0].target) == {'pesid2',
                                                   'pesid3'}, fail_description

    # 2. Verify that only repositories valid for the current IPU are produced
    pesid_repos = repo_mapping.repositories
    fail_description = 'Actor produced incorrect number of IPU-relevant pesid repos.'
    assert len(pesid_repos) == 3, fail_description

    expected_pesid_repos = [
        PESIDRepositoryEntry(pesid='pesid1',
                             major_version='7',
                             repoid='some-rhel-7-repoid',
                             arch='x86_64',
                             repo_type='rpm',
                             channel='eus',
                             rhui=''),
        PESIDRepositoryEntry(pesid='pesid2',
                             major_version='8',
                             repoid='some-rhel-8-repoid1',
                             arch='x86_64',
                             repo_type='rpm',
                             channel='eus',
                             rhui=''),
        PESIDRepositoryEntry(pesid='pesid3',
                             major_version='8',
                             repoid='some-rhel-8-repoid2',
                             arch='x86_64',
                             repo_type='rpm',
                             channel='eus',
                             rhui=''),
    ]

    fail_description = 'Expected pesid repo is not present in the deserialization output.'
    for expected_pesid_repo in expected_pesid_repos:
        assert expected_pesid_repo in pesid_repos, fail_description
예제 #11
0
 def process(self):
     scan_repositories()