Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkrhui: Produce TargetUserSpacePreupgradeTasks + refactoring #699

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions repos/system_upgrade/common/actors/cloud/checkrhui/actor.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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'),
Expand All @@ -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(
Expand All @@ -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']],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is in common, do we want to keep el8_pkg and el7_pkg? Renaming those to old_pkg and new_pkg would make much more sense in common context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shaded-enmity Good point. We could define the new/old variables in the begining of the begining and than just use these variables everywhere to work with the map in the share library.

to_remove=[info['el7_pkg']]),
)
self.produce(
RHUIInfo(provider=provider),
RequiredTargetUserspacePackages(packages=[info['el8_pkg']]), # deprecated
TargetUserSpacePreupgradeTasks(install_rpms=[info['el8_pkg']]),
)
return
Original file line number Diff line number Diff line change
Expand Up @@ -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. <http://bugzilla.redhat.com/bugzilla>'
Expand Down Expand Up @@ -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