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

Simplify rhui #1057

Merged
merged 2 commits into from
Nov 10, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

from leapp import reporting
from leapp.libraries.actor import checketcreleasever
from leapp.libraries.common.testutils import (
create_report_mocked,
CurrentActorMocked,
logger_mocked
)
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked, logger_mocked
from leapp.libraries.stdlib import api
from leapp.models import PkgManagerInfo, Report, RHUIInfo
from leapp.models import (
PkgManagerInfo,
Report,
RHUIInfo,
TargetRHUIPostInstallTasks,
TargetRHUIPreInstallTasks,
TargetRHUISetupInfo
)


@pytest.mark.parametrize('exists', [True, False])
Expand Down Expand Up @@ -55,9 +58,24 @@ def test_etc_releasever_empty(monkeypatch):
assert api.current_logger.dbgmsg


def mk_rhui_info():
preinstall_tasks = TargetRHUIPreInstallTasks()
postinstall_tasks = TargetRHUIPostInstallTasks()
setup_info = TargetRHUISetupInfo(preinstall_tasks=preinstall_tasks, postinstall_tasks=postinstall_tasks)
rhui_info = RHUIInfo(provider='aws',
src_client_pkg_names=['rh-amazon-rhui-client'],
target_client_pkg_names=['rh-amazon-rhui-client'],
target_client_setup_info=setup_info)
return rhui_info


@pytest.mark.parametrize('is_rhui', [True, False])
def test_etc_releasever_rhui(monkeypatch, is_rhui):
rhui_msg = [RHUIInfo(provider='aws')] if is_rhui else []
if is_rhui:
rhui_msg = [mk_rhui_info()]
else:
rhui_msg = []

expected_rel_ver = '6.10'

mocked_report = create_report_mocked()
Expand Down Expand Up @@ -92,7 +110,9 @@ def test_etc_releasever_neither(monkeypatch):


def test_etc_releasever_both(monkeypatch):
msgs = [RHUIInfo(provider='aws'), PkgManagerInfo(etc_releasever='7.7')]
rhui_info = mk_rhui_info()

msgs = [rhui_info, PkgManagerInfo(etc_releasever='7.7')]
expected_rel_ver = '6.10'

mocked_report = create_report_mocked()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from leapp import reporting
from leapp.libraries.common import rhui
from leapp.libraries.common.config.version import get_source_major_version
from leapp.libraries.common.rpms import has_package
from leapp.libraries.stdlib import api
from leapp.models import FirmwareFacts, HybridImage, InstalledRPM
Expand All @@ -20,8 +21,20 @@ def is_grubenv_symlink_to_efi():

def is_azure_agent_installed():
"""Check whether 'WALinuxAgent' package is installed."""
upg_path = rhui.get_upg_path()
agent_pkg = rhui.RHUI_CLOUD_MAP[upg_path].get('azure', {}).get('agent_pkg', '')
src_ver_major = get_source_major_version()

family = rhui.RHUIFamily(rhui.RHUIProvider.AZURE)
azure_setups = rhui.RHUI_SETUPS.get(family, [])

agent_pkg = None
for setup in azure_setups:
if setup.os_version == src_ver_major:
agent_pkg = setup.extra_info.get('agent_pkg')
break

if not agent_pkg:
return False

return has_package(InstalledRPM, agent_pkg)


Expand Down
93 changes: 3 additions & 90 deletions repos/system_upgrade/common/actors/cloud/checkrhui/actor.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import os

from leapp import reporting
from leapp.actors import Actor
from leapp.libraries.common import rhsm, rhui
from leapp.libraries.common.config.version import get_source_major_version
from leapp.libraries.common.rpms import has_package
from leapp.libraries.stdlib import api
from leapp.libraries.actor import checkrhui as checkrhui_lib
from leapp.models import (
CopyFile,
DNFPluginTask,
Expand All @@ -16,7 +10,7 @@
RpmTransactionTasks,
TargetUserSpacePreupgradeTasks
)
from leapp.reporting import create_report, Report
from leapp.reporting import Report
from leapp.tags import FactsPhaseTag, IPUWorkflowTag


Expand All @@ -40,85 +34,4 @@ class CheckRHUI(Actor):
tags = (FactsPhaseTag, IPUWorkflowTag)

def process(self):
upg_path = rhui.get_upg_path()
for provider, info in rhui.RHUI_CLOUD_MAP[upg_path].items():
if has_package(InstalledRPM, info['src_pkg']):
# we need to do this workaround in order to overcome our RHUI handling limitation
# in case there are more client packages on the source system
# @Note(mhecko): Azure has changed the structure of their images to not use a pair of RHUI clients and
# # instead they started to use a single package. However, it could happen that a user
# # does not run `dnf upgrade` and thus has both packages installed.
if 'azure' in info['src_pkg']:
azure_sap_variants = ['azure-sap-ha', 'azure-sap-apps']
for azure_sap_variant in azure_sap_variants:
sap_variant_info = rhui.RHUI_CLOUD_MAP[upg_path][azure_sap_variant]
if has_package(InstalledRPM, sap_variant_info['src_pkg']):
info = sap_variant_info
provider = azure_sap_variant

if provider.startswith('google'):
rhui_dir = api.get_common_folder_path('rhui')
repofile = os.path.join(rhui_dir, provider, 'leapp-{}.repo'.format(provider))
api.produce(
TargetUserSpacePreupgradeTasks(
copy_files=[CopyFile(src=repofile, dst='/etc/yum.repos.d/leapp-google-copied.repo')]
)
)

if not rhsm.skip_rhsm():
create_report([
reporting.Title('Upgrade initiated with RHSM on public cloud with RHUI infrastructure'),
reporting.Summary(
'Leapp detected this system is on public cloud with RHUI infrastructure '
'but the process was initiated without "--no-rhsm" command line option '
'which implies RHSM usage (valid subscription is needed).'
),
reporting.Severity(reporting.Severity.INFO),
reporting.Groups([reporting.Groups.PUBLIC_CLOUD]),
])
return

# When upgrading with RHUI we cannot switch certs and let RHSM provide us repos for target OS content.
# Instead, Leapp's provider-specific package containing target OS certs and repos has to be installed.
if not has_package(InstalledRPM, info['leapp_pkg']):
create_report([
reporting.Title('Package "{}" is missing'.format(info['leapp_pkg'])),
reporting.Summary(
'On {} using RHUI infrastructure, a package "{}" is needed for '
'in-place upgrade'.format(provider.upper(), info['leapp_pkg'])
),
reporting.Severity(reporting.Severity.HIGH),
reporting.RelatedResource('package', info['leapp_pkg']),
reporting.Groups([reporting.Groups.INHIBITOR]),
reporting.Groups([reporting.Groups.PUBLIC_CLOUD, reporting.Groups.RHUI]),
reporting.Remediation(commands=[['yum', 'install', '-y', info['leapp_pkg']]])
])
return

# there are several "variants" related to the *AWS* provider (aws, aws-sap)
if provider.startswith('aws'):
# We have to disable Amazon-id plugin in the initramdisk phase as the network
# is down at the time
self.produce(DNFPluginTask(name='amazon-id', disable_in=['upgrade']))

# If source OS and target OS packages differ we must remove the source pkg, and install the target pkg.
# If the packages do not differ, it is sufficient to upgrade them during the upgrade
if info['src_pkg'] != info['target_pkg']:
self.produce(RpmTransactionTasks(to_install=[info['target_pkg']]))
self.produce(RpmTransactionTasks(to_remove=[info['src_pkg']]))

# Although SAP systems on Azure should not rely on a pair of RHUI clients, it is still possible
# that the source system has both clients installed, and it is safer to remove both of them.
azure_nonsap_pkg = None
if provider == 'azure-sap-ha':
azure_nonsap_pkg = rhui.RHUI_CLOUD_MAP[upg_path]['azure']['src_pkg']
elif provider == 'azure-sap-apps':
# SAP Apps systems have EUS content channel from RHEL8+
src_rhel_content_type = 'azure' if get_source_major_version() == '7' else 'azure-eus'
azure_nonsap_pkg = rhui.RHUI_CLOUD_MAP[upg_path][src_rhel_content_type]['src_pkg']
if azure_nonsap_pkg and has_package(InstalledRPM, azure_nonsap_pkg):
self.produce(RpmTransactionTasks(to_remove=[azure_nonsap_pkg]))

self.produce(RHUIInfo(provider=provider))
self.produce(RequiredTargetUserspacePackages(packages=[info['target_pkg']]))
return
checkrhui_lib.process()
Loading
Loading