From 07a9c5c3759afa4e252ad3e1c49451150791f1d6 Mon Sep 17 00:00:00 2001 From: Petr Stodulka Date: Fri, 30 Jul 2021 11:26:21 +0200 Subject: [PATCH] checkrhui: Produce TargetUserSpacePreupgradeTasks + refactoring The RequiredTargetUserspacePackages model has been deprecated in favor of the TargetUserSpacePreupgradeTasks model. Keeping the original functionality + produce the new msg as well. Additionally the actor is a little bit refactored. --- .../common/actors/cloud/checkrhui/actor.py | 33 ++++++++++++------- .../tests/component_test_checkrhui.py | 17 +++++----- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/repos/system_upgrade/common/actors/cloud/checkrhui/actor.py b/repos/system_upgrade/common/actors/cloud/checkrhui/actor.py index 819437cb3f..013c6039ed 100644 --- a/repos/system_upgrade/common/actors/cloud/checkrhui/actor.py +++ b/repos/system_upgrade/common/actors/cloud/checkrhui/actor.py @@ -1,19 +1,21 @@ +from leapp import reporting from leapp.actors import Actor -from leapp.libraries.common.rpms import has_package +from leapp.libraries.common import rhsm, rhui, rpms from leapp.models import ( DNFPluginTask, InstalledRPM, KernelCmdlineArg, RHUIInfo, - RequiredTargetUserspacePackages, + RequiredTargetUserspacePackages, # deprecated RpmTransactionTasks, + TargetUserSpacePreupgradeTasks, ) from leapp.reporting import Report, create_report -from leapp import reporting from leapp.tags import ChecksPhaseTag, IPUWorkflowTag -from leapp.libraries.common import rhsm, rhui +from leapp.utils.deprecation import suppress_deprecation +@suppress_deprecation(RequiredTargetUserspacePackages) class CheckRHUI(Actor): """ Check if system is using RHUI infrastructure (on public cloud) and send messages to @@ -23,18 +25,20 @@ class CheckRHUI(Actor): name = 'checkrhui' consumes = (InstalledRPM) produces = ( + DNFPluginTask, KernelCmdlineArg, RHUIInfo, - RequiredTargetUserspacePackages, - Report, DNFPluginTask, + Report, + RequiredTargetUserspacePackages, # deprecated RpmTransactionTasks, + TargetUserSpacePreupgradeTasks, ) tags = (ChecksPhaseTag, IPUWorkflowTag) def process(self): arch = self.configuration.architecture for provider, info in rhui.RHUI_CLOUD_MAP[arch].items(): - if has_package(InstalledRPM, info['el7_pkg']): + if rpms.has_package(InstalledRPM, info['el7_pkg']): if not rhsm.skip_rhsm(): create_report([ reporting.Title('Upgrade initiated with RHSM on public cloud with RHUI infrastructure'), @@ -48,7 +52,7 @@ def process(self): ]) return # AWS RHUI package is provided and signed by RH but the Azure one not - if not has_package(InstalledRPM, info['leapp_pkg']): + if not rpms.has_package(InstalledRPM, info['leapp_pkg']): create_report([ reporting.Title('Package "{}" is missing'.format(info['leapp_pkg'])), reporting.Summary( @@ -68,8 +72,13 @@ def process(self): self.produce(DNFPluginTask(name='amazon-id', disable_in=['upgrade'])) # if RHEL7 and RHEL8 packages differ, we cannot rely on simply updating them if info['el7_pkg'] != info['el8_pkg']: - self.produce(RpmTransactionTasks(to_install=[info['el8_pkg']])) - self.produce(RpmTransactionTasks(to_remove=[info['el7_pkg']])) - self.produce(RHUIInfo(provider=provider)) - self.produce(RequiredTargetUserspacePackages(packages=[info['el8_pkg']])) + self.produce(RpmTransactionTasks( + to_install=[info['el8_pkg']], + to_remove=[info['el7_pkg']]), + ) + self.produce( + RHUIInfo(provider=provider), + RequiredTargetUserspacePackages(packages=[info['el8_pkg']]), # deprecated + TargetUserSpacePreupgradeTasks(install_rpms=[info['el8_pkg']]), + ) return diff --git a/repos/system_upgrade/common/actors/cloud/checkrhui/tests/component_test_checkrhui.py b/repos/system_upgrade/common/actors/cloud/checkrhui/tests/component_test_checkrhui.py index ee9697902f..e36a9d6d3c 100644 --- a/repos/system_upgrade/common/actors/cloud/checkrhui/tests/component_test_checkrhui.py +++ b/repos/system_upgrade/common/actors/cloud/checkrhui/tests/component_test_checkrhui.py @@ -2,17 +2,18 @@ import pytest -from leapp.snactor.fixture import current_actor_context +from leapp.libraries.common import rhsm +from leapp.libraries.common.config import mock_configs from leapp.models import ( - InstalledRedHatSignedRPM, InstalledRPM, - RPM, + InstalledRedHatSignedRPM, RHUIInfo, - RequiredTargetUserspacePackages, + RPM, + RequiredTargetUserspacePackages, # deprecated + TargetUserSpacePreupgradeTasks, ) from leapp.reporting import Report -from leapp.libraries.common.config import mock_configs -from leapp.libraries.common import rhsm +from leapp.snactor.fixture import current_actor_context RH_PACKAGER = 'Red Hat, Inc. ' @@ -57,5 +58,5 @@ def test_check_rhui_actor( current_actor_context.run(config_model=mock_configs.CONFIG) assert bool(current_actor_context.consume(Report)) is msgs_received.report assert bool(current_actor_context.consume(RHUIInfo)) is msgs_received.rhui_info - assert bool(current_actor_context.consume( - RequiredTargetUserspacePackages)) is msgs_received.req_target_userspace + for msg in [RequiredTargetUserspacePackages, TargetUserSpacePreupgradeTasks]: + assert bool(current_actor_context.consume(msg)) is msgs_received.req_target_userspace