def test_resolve_conflicting_requests(monkeypatch):
    """
    Verifies that the algorithm correctly resolves conflicting pes events.
    """
    monkeypatch.setattr(peseventsscanner, 'map_repositories', lambda x: x)
    monkeypatch.setattr(peseventsscanner,
                        'filter_out_pkgs_in_blacklisted_repos', lambda x: x)

    events = [
        Event(1, Action.SPLIT, {Package('sip-devel', 'repo', None)}, {
            Package('python3-sip-devel', 'repo', None),
            Package('sip', 'repo', None)
        }, (7, 6), (8, 0), []),
        Event(2, Action.SPLIT, {Package('sip', 'repo', None)}, {
            Package('python3-pyqt5-sip', 'repo', None),
            Package('python3-sip', 'repo', None)
        }, (7, 6), (8, 0), [])
    ]
    installed_pkgs = {('sip', None), ('sip-devel', None)}

    tasks = process_events([(8, 0)], events, installed_pkgs)

    assert tasks[Task.INSTALL] == {
        ('python3-sip-devel', None): 'repo',
        ('python3-pyqt5-sip', None): 'repo',
        ('python3-sip', None): 'repo'
    }
    assert tasks[Task.REMOVE] == {('sip-devel', None): 'repo'}
    assert tasks[Task.KEEP] == {('sip', None): 'repo'}
Exemple #2
0
def test_resolve_conflicting_requests(monkeypatch):
    monkeypatch.setattr(peseventsscanner, 'map_repositories', lambda x: x)
    monkeypatch.setattr(peseventsscanner,
                        'filter_out_pkgs_in_blacklisted_repos', lambda x: x)

    events = [
        Event(1, Action.split, {'sip-devel': 'repo'}, {
            'python3-sip-devel': 'repo',
            'sip': 'repo'
        }, (7, 6), (8, 0), []),
        Event(2, Action.split, {'sip': 'repo'}, {
            'python3-pyqt5-sip': 'repo',
            'python3-sip': 'repo'
        }, (7, 6), (8, 0), [])
    ]
    installed_pkgs = {'sip', 'sip-devel'}

    tasks = process_events([(8, 0)], events, installed_pkgs)

    assert tasks[Task.install] == {
        'python3-sip-devel': 'repo',
        'python3-pyqt5-sip': 'repo',
        'python3-sip': 'repo'
    }
    assert tasks[Task.remove] == {'sip-devel': 'repo'}
    assert tasks[Task.keep] == {'sip': 'repo'}
def test_process_events(monkeypatch):
    """
    Verifies that the event processing algorithm works as expected.
    """
    monkeypatch.setattr(peseventsscanner,
                        '_get_repositories_mapping',
                        lambda dummy_target_pesids: {'rhel8-repo': 'rhel8-mapped'})
    monkeypatch.setattr(peseventsscanner, 'get_repositories_blacklisted', get_repos_blacklisted_mocked(set()))

    events = [
        Event(1, Action.SPLIT, {'original': 'rhel7-repo'}, {'split01': 'rhel8-repo', 'split02': 'rhel8-repo'},
              (7, 6), (8, 0), []),
        Event(2, Action.REMOVED, {'removed': 'rhel7-repo'}, {}, (7, 6), (8, 0), []),
        Event(3, Action.PRESENT, {'present': 'rhel8-repo'}, {}, (7, 6), (8, 0), []),
        # this package is present at the start, gets removed and then reintroduced
        Event(4, Action.REMOVED, {'reintroduced': 'rhel7-repo'}, {}, (7, 6), (8, 0), []),
        Event(5, Action.PRESENT, {'reintroduced': 'rhel8-repo'}, {}, (8, 0), (8, 1), []),
        # however, this package was never there
        Event(6, Action.REMOVED, {'neverthere': 'rhel7-repo'}, {}, (7, 6), (8, 0), []),
        Event(7, Action.PRESENT, {'neverthere': 'rhel8-repo'}, {}, (8, 0), (8, 1), [])]
    installed_pkgs = {'original', 'removed', 'present', 'reintroduced'}
    tasks = process_events([(8, 0), (8, 1)], events, installed_pkgs)

    assert tasks[Task.INSTALL] == {'split02': 'rhel8-mapped', 'split01': 'rhel8-mapped'}
    assert tasks[Task.REMOVE] == {'removed': 'rhel7-repo', 'original': 'rhel7-repo'}
    assert tasks[Task.KEEP] == {'present': 'rhel8-mapped', 'reintroduced': 'rhel8-mapped'}
def test_merge_events_relevance_assessment(monkeypatch, installed_pkgs,
                                           expected_relevance):
    """
    Verifies that the relevance of the MERGED events is correctly assessed when processing events.
    """
    monkeypatch.setattr(peseventsscanner, 'map_repositories', lambda x: x)
    monkeypatch.setattr(peseventsscanner,
                        'filter_out_pkgs_in_blacklisted_repos', lambda x: x)

    events = [
        Event(1, Action.REPLACED, {Package('pkg0', 'repo-in', None)},
              {Package('pkg4', 'repo-out', None)}, (7, 8), (7, 9), []),
        Event(
            2,
            Action.MERGED,
            {
                Package('pkg1', 'repo-in', None),
                Package('pkg2', 'repo-in', None)
            },
            {Package('pkg3', 'repo-out', None)},
            (7, 9),
            (8, 0),
            [],
        ),
        Event(
            3,
            Action.MERGED,
            {
                Package('pkg1', 'repo-in', 'wuzza:11'),
                Package('pkg2', 'repo-in', 'wuzza:11')
            },
            {Package('pkg3', 'repo-out', None)},
            (7, 9),
            (8, 0),
            [],
        )
    ]

    tasks = process_events([(7, 9), (8, 0)], events, installed_pkgs)

    if expected_relevance:
        assert not set(tasks[Task.INSTALL].keys()) - {('pkg3', None),
                                                      ('pkg4', None)}
        removed_packages = set()
        if any(p[1] for p in installed_pkgs):
            removed_packages = installed_pkgs
        if ('pkg0', None) in installed_pkgs:
            removed_packages.add(('pkg0', None))
        if ('pkg1', None) in installed_pkgs or ('pkg2',
                                                None) in installed_pkgs:
            removed_packages.add(('pkg1', None))
            removed_packages.add(('pkg2', None))

        assert not set(tasks[Task.REMOVE].keys()) - removed_packages
    else:
        assert not tasks[Task.INSTALL]
        assert not tasks[Task.REMOVE]
def test_request_pesid_repo_not_mapped_by_default(monkeypatch, source_repoid, expected_target_repoid):
    """
    Tests whether a target repository that is not mapped by default (e.g. CRB)
    is requested to be enabled on the target system if it results from the relevant events.

    Note: Since the resulting target repository is not mapped by default from the enabled repositories,
          the data handler should fail to get expected repoids for the given pesid as it works with enabled
          repositories. Therefor, this test tests whether the fallback lookup with representative repository works.
    """

    repositories_mapping = RepositoriesMapping(
        mapping=[
            RepoMapEntry(source='rhel7-base', target=['rhel8-BaseOS', 'rhel8-AppStream']),
            RepoMapEntry(source='rhel7-optional', target=['rhel8-CRB']),
        ],
        repositories=[
            PESIDRepositoryEntry(pesid='rhel7-base', major_version='7', repoid='rhel7-base-repoid',
                                 arch='x86_64', repo_type='rpm', channel='ga', rhui=''),
            PESIDRepositoryEntry(pesid='rhel7-base', major_version='7', repoid='rhel7-base-repoid-eus',
                                 arch='x86_64', repo_type='rpm', channel='eus', rhui=''),
            PESIDRepositoryEntry(pesid='rhel7-optional', major_version='7', repoid='rhel7-optional-repoid',
                                 arch='x86_64', repo_type='rpm', channel='ga', rhui=''),
            PESIDRepositoryEntry(pesid='rhel8-BaseOS', major_version='8', repoid='rhel8-baseos-repoid',
                                 arch='x86_64', repo_type='rpm', channel='ga', rhui=''),
            PESIDRepositoryEntry(pesid='rhel8-BaseOS', major_version='8', repoid='rhel8-baseos-repoid-eus',
                                 arch='x86_64', repo_type='rpm', channel='eus', rhui=''),
            PESIDRepositoryEntry(pesid='rhel8-AppStream', major_version='8', repoid='rhel8-appstream-repoid',
                                 arch='x86_64', repo_type='rpm', channel='ga', rhui=''),
            PESIDRepositoryEntry(pesid='rhel8-CRB', major_version='8', repoid='rhel8-crb-repoid',
                                 arch='x86_64', repo_type='rpm', channel='ga', rhui=''),
            PESIDRepositoryEntry(pesid='rhel8-CRB', major_version='8', repoid='rhel8-crb-repoid-eus',
                                 arch='x86_64', repo_type='rpm', channel='eus', rhui=''),
        ])

    monkeypatch.setattr(peseventsscanner, '_get_enabled_repoids', lambda: {source_repoid})
    monkeypatch.setattr(api,
                        'current_actor',
                        CurrentActorMocked(msgs=[repositories_mapping], src_ver='7.9', dst_ver='8.4'))

    event = Event(1, Action.MOVED, {'test-pkg': 'rhel7-base'}, {'test-pkg': 'rhel8-CRB'},
                  (7, 9), (8, 0), [])
    installed_pkgs = {'test-pkg'}

    tasks = process_events([(8, 0)], [event], installed_pkgs)

    assert tasks[Task.KEEP] == {'test-pkg': expected_target_repoid}
def test_process_modular_events(monkeypatch):
    monkeypatch.setattr(peseventsscanner, 'map_repositories', lambda x: x)
    monkeypatch.setattr(peseventsscanner,
                        'filter_out_pkgs_in_blacklisted_repos', lambda x: x)

    events = [
        # match the right modular package without touching the ones with absent or different module/stream
        # in practice, installed packages can't have the same name, just testing that it matches the right one
        Event(1,
              Action.REMOVED, {Package('removed', 'repo', ('module', '42'))},
              set(), (8, 4), (9, 0), []),
        Event(2, Action.SPLIT,
              {Package('split_in', 'repo', ('splitin', 'foo'))}, {
                  Package('split_out1', 'repo', None),
                  Package('split_out2', 'repo', ('splitout', 'foo'))
              }, (8, 4), (9, 0), []),
        Event(3, Action.SPLIT,
              {Package('split_in', 'repo', ('splitin', 'bar'))}, {
                  Package('split_out3', 'repo', None),
                  Package('split_out2', 'repo', ('splitout', 'bar'))
              }, (8, 4), (9, 0), []),
    ]
    installed_pkgs = {('removed', ('module', '42')),
                      ('removed', ('model', '42')),
                      ('removed', ('module', '420')), ('removed', None),
                      ('split_in', ('splitin', 'foo'))}

    tasks = process_events([(9, 0)], events, installed_pkgs)

    assert ('removed',
            ('module',
             '42')) in tasks[Task.REMOVE]  # name, module and stream match
    assert ('removed', ('model',
                        '42')) not in tasks[Task.REMOVE]  # different module
    assert ('removed', ('module',
                        '420')) not in tasks[Task.REMOVE]  # different stream
    assert ('removed', None) not in tasks[Task.REMOVE]  # no module stream

    assert ('split_in', ('splitin', 'foo')) in tasks[Task.REMOVE]
    assert ('split_out1', None) in tasks[Task.INSTALL]
    assert ('split_out2', ('splitout', 'foo')) in tasks[Task.INSTALL]
    assert ('split_in', ('splitin', 'bar')) not in tasks[Task.REMOVE]
    assert ('split_out3', None) not in tasks[Task.INSTALL]
    assert ('split_out2', ('splitout', 'bar')) not in tasks[Task.INSTALL]
Exemple #7
0
def test_process_events(monkeypatch):
    monkeypatch.setattr(peseventsscanner, '_get_repositories_mapping',
                        lambda: {'rhel8-repo': 'rhel8-mapped'})
    monkeypatch.setattr(peseventsscanner, 'get_repositories_blacklisted',
                        get_repos_blacklisted_mocked(set()))

    events = [
        Event(1, Action.split, {'original': 'rhel7-repo'}, {
            'split01': 'rhel8-repo',
            'split02': 'rhel8-repo'
        }, (7, 6), (8, 0), []),
        Event(2, Action.removed, {'removed': 'rhel7-repo'}, {}, (7, 6), (8, 0),
              []),
        Event(3, Action.present, {'present': 'rhel8-repo'}, {}, (7, 6), (8, 0),
              []),
        # this package is present at the start, gets removed and then reintroduced
        Event(4, Action.removed, {'reintroduced': 'rhel7-repo'}, {}, (7, 6),
              (8, 0), []),
        Event(5, Action.present, {'reintroduced': 'rhel8-repo'}, {}, (8, 0),
              (8, 1), []),
        # however, this package was never there
        Event(6, Action.removed, {'neverthere': 'rhel7-repo'}, {}, (7, 6),
              (8, 0), []),
        Event(7, Action.present, {'neverthere': 'rhel8-repo'}, {}, (8, 0),
              (8, 1), [])
    ]
    installed_pkgs = {'original', 'removed', 'present', 'reintroduced'}
    tasks = process_events([(8, 0), (8, 1)], events, installed_pkgs)

    assert tasks[Task.install] == {
        'split02': 'rhel8-mapped',
        'split01': 'rhel8-mapped'
    }
    assert tasks[Task.remove] == {
        'removed': 'rhel7-repo',
        'original': 'rhel7-repo'
    }
    assert tasks[Task.keep] == {
        'present': 'rhel8-mapped',
        'reintroduced': 'rhel8-mapped'
    }
def test_merge_events_relevance_assessment(monkeypatch, installed_pkgs, expected_relevance):
    """
    Verifies that the relevance of the MERGED events is correctly assessed when processing events.
    """
    monkeypatch.setattr(peseventsscanner, 'map_repositories', lambda x: x)
    monkeypatch.setattr(peseventsscanner, 'filter_out_pkgs_in_blacklisted_repos', lambda x: x)

    events = [
        Event(1, Action.REPLACED, {'pkg0': 'repo-in'}, {'pkg1': 'repo-in'}, (7, 8), (7, 9), []),
        Event(2, Action.MERGED, {'pkg1': 'repo-in', 'pkg2': 'repo-in'}, {'pkg3': 'repo-out'}, (7, 9), (8, 0), [])
    ]

    tasks = process_events([(7, 9), (8, 0)], events, installed_pkgs)

    if expected_relevance:
        assert tasks[Task.INSTALL] == {'pkg3': 'repo-out'}
        if 'pkg0' in installed_pkgs:
            assert tasks[Task.REMOVE] == {'pkg0': 'repo-in', 'pkg2': 'repo-in'}
        else:
            assert tasks[Task.REMOVE] == {'pkg1': 'repo-in', 'pkg2': 'repo-in'}
    else:
        assert not tasks[Task.INSTALL]
        assert not tasks[Task.REMOVE]