From 59a371c5aa15f77e3cd90f0eb62ea334204bc0fe Mon Sep 17 00:00:00 2001 From: Matej Matuska Date: Thu, 23 Nov 2023 17:38:35 +0100 Subject: [PATCH] pes_events_scanner: Ignore Leapp related PES events When PES events are added for all the Leapp related packages, we need to make sure to ignore them in `pes_events_scanner` to make sure they are *not* taken into account during the RPM upgrade transaction as we don't want to upgrade them or want to handle their upgrade in a different way. Jira: OAMG-5645 --- .../libraries/pes_events_scanner.py | 16 +++++ .../tests/test_pes_event_scanner.py | 61 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/repos/system_upgrade/common/actors/peseventsscanner/libraries/pes_events_scanner.py b/repos/system_upgrade/common/actors/peseventsscanner/libraries/pes_events_scanner.py index f8d8dcfce1..27a4642012 100644 --- a/repos/system_upgrade/common/actors/peseventsscanner/libraries/pes_events_scanner.py +++ b/repos/system_upgrade/common/actors/peseventsscanner/libraries/pes_events_scanner.py @@ -480,6 +480,21 @@ def apply_transaction_configuration(source_pkgs): return source_pkgs_with_conf_applied +def remove_leapp_related_events(events): + leapp_pkgs = [ + 'leapp', 'leapp-deps', 'leapp-upgrade-el7toel8', 'leapp-upgrade-el8toel9', + 'leapp-upgrade-el7toel8-deps', 'leapp-upgrade-el8toel9-deps', 'python2-leapp', + 'python3-leapp', 'snactor' + ] + res = [] + for event in events: + if not any(pkg.name in leapp_pkgs for pkg in event.in_pkgs): + res.append(event) + else: + api.current_logger().debug('Filtered out leapp related event, event id: {}'.format(event.id)) + return res + + def process(): # Retrieve data - installed_pkgs, transaction configuration, pes events events = get_pes_events('/etc/leapp/files', 'pes-events.json') @@ -494,6 +509,7 @@ def process(): # packages of the target system, so we can distinguish what needs to be repomapped repoids_of_source_pkgs = {pkg.repository for pkg in source_pkgs} + events = remove_leapp_related_events(events) events = remove_undesired_events(events, releases) # Apply events - compute what packages should the target system have diff --git a/repos/system_upgrade/common/actors/peseventsscanner/tests/test_pes_event_scanner.py b/repos/system_upgrade/common/actors/peseventsscanner/tests/test_pes_event_scanner.py index 8122e54159..739ad79763 100644 --- a/repos/system_upgrade/common/actors/peseventsscanner/tests/test_pes_event_scanner.py +++ b/repos/system_upgrade/common/actors/peseventsscanner/tests/test_pes_event_scanner.py @@ -402,3 +402,64 @@ def test_pkgs_are_demodularized_when_crossing_major_version(monkeypatch): } assert demodularized_pkgs == {Package('demodularized', 'repo', ('module-demodularized', 'stream'))} assert target_pkgs == expected_target_pkgs + + +def test_remove_leapp_related_events(): + # these are just hypothetical and not necessarily correct + package_set_two_leapp = {Package('leapp-upgrade-el7toel8', 'repoid-rhel7', None), + Package('leapp-upgrade-el7toel8-deps', 'repoid-rhel7', None)} + package_set_one_leapp = {Package('leapp-upgrade-el7toel8', 'repoid-rhel7', None), + Package('other', 'repoid-rhel7', None)} + in_events = [ + Event(1, Action.PRESENT, {Package('leapp', 'repoid-rhel7', None)}, + {Package('leapp', 'repoid-rhel8', None)}, (7, 0), (8, 0), []), + + Event(1, Action.RENAMED, {Package('leapp-deps', 'repoid-rhel7', None)}, + {Package('leapp-deps', 'repoid-rhel8', None)}, (7, 0), (8, 0), []), + Event(1, Action.RENAMED, {Package('leapp-upgrade-el7toel8', 'repoid-rhel7', None)}, + {Package('leapp-upgrade-el8toel9', 'repoid-rhel8', None)}, (7, 0), (8, 0), []), + Event(2, Action.RENAMED, {Package('leapp-upgrade-el7toel8-deps', 'repoid-rhel7', None)}, + {Package('leapp-upgrade-el8toel9-deps', 'repoid-rhel8', None)}, (7, 0), (8, 0), []), + Event(2, Action.PRESENT, {Package('snactor', 'repoid-rhel7', None)}, + {Package('snactor', 'repoid-rhel8', None)}, (7, 0), (8, 0), []), + Event(2, Action.REPLACED, {Package('python2-leapp', 'repoid-rhel7', None)}, + {Package('python3-leapp', 'repoid-rhel8', None)}, + (7, 0), (8, 0), []), + + Event(1, Action.DEPRECATED, {Package('leapp-upgrade-el8toel9', 'repoid-rhel8', None)}, + {Package('leapp-upgrade-el8toel9', 'repoid-rhel9', None)}, (8, 0), (9, 0), []), + Event(2, Action.REMOVED, {Package('leapp-upgrade-el8toel9-deps', 'repoid-rhel8', None)}, + {}, (8, 0), (9, 0), []), + Event(1, Action.RENAMED, {Package('leapp-deps', 'repoid-rhel8', None)}, + {Package('leapp-deps', 'repoid-rhel9', None)}, (8, 0), (9, 0), []), + Event(2, Action.PRESENT, {Package('snactor', 'repoid-rhel8', None)}, + {Package('snactor', 'repoid-rhel9', None)}, (8, 0), (9, 0), []), + Event(2, Action.REMOVED, {Package('python3-leapp', 'repoid-rhel8', None)}, + {Package('snactor', 'repoid-rhel9', None)}, (8, 0), (9, 0), []), + + Event(2, Action.PRESENT, {Package('other-pkg', 'repoid-rhel8', None)}, + {Package('other-pkg', 'repoid-rhel9', None)}, (7, 0), (8, 0), []), + Event(2, Action.PRESENT, {Package('other-pkg-with-leapp-in-the-name', 'repoid-rhel7', None)}, + {Package('other-pkg-with-leapp-in-the-name', 'repoid-rhel8', None)}, (7, 0), (8, 0), []), + + # multiple leapp packages in in_pkgs + Event(1, Action.MERGED, package_set_two_leapp, {Package('leapp-upgrade-el7toel8', 'repoid-rhel8', None)}, + (7, 0), (8, 0), []), + + # multiple leapp packages in out_pkgs + Event(1, Action.SPLIT, {Package('leapp-upgrade-el7toel8', 'repoid-rhel7', None)}, + package_set_two_leapp, (7, 0), (8, 0), []), + + # leapp and other pkg in in_pkgs + Event(1, Action.MERGED, package_set_one_leapp, {Package('leapp', 'repoid-rhel8', None)}, + (7, 0), (8, 0), []), + ] + expected_out_events = [ + Event(2, Action.PRESENT, {Package('other-pkg', 'repoid-rhel8', None)}, + {Package('other-pkg', 'repoid-rhel9', None)}, (7, 0), (8, 0), []), + Event(2, Action.PRESENT, {Package('other-pkg-with-leapp-in-the-name', 'repoid-rhel7', None)}, + {Package('other-pkg-with-leapp-in-the-name', 'repoid-rhel8', None)}, (7, 0), (8, 0), []), + ] + + out_events = pes_events_scanner.remove_leapp_related_events(in_events) + assert out_events == expected_out_events