Skip to content

Commit

Permalink
rhui: bootstrap target rhui clients in scratch container
Browse files Browse the repository at this point in the history
In order to upgrade a RHUI system leapp uses custom `leapp-rhui-
X` packages providing leapp with necessary repository definitions as
well as certs and keys to access these repositories. The content of
the `leapp-rhui-X` packages is therefore almost identical to the RHUI
client(s) found on the target systems, implying that leapp's rhui
packages must actively mirror any changes to the target client packages.
This patch modifies leapp so that leapp uses the `leapp-rhui-X` package
only to provide a definion of the repository where a target RHUI client
can be found. The current RHUI client and target RHUI client is then
(bootstrapped) atomically swapped in the scratch container, allowing the
upgrade process to access target content. This change thus minimizes
the effort put into maintaining leapp-rhui-X.

This patch also does redesigns the "cloud map" to contain declarative
descriptions of setups, allowing to produce different the client
bootstrap steps if desired (not implemented). The new map also contains
information about content channel used on known rhui systems, laying the
necessary foundation for better error messages when the user forgets to
run leapp with --channel.

Finally, the RHUI-handling logic has been mostly isolated into a fully
unit-tested actor, whereas the implemented userspacegen modifications
have the nature of somehow blindly following the instructions produced
by the RHUI actor.

Jira: OAMG-8599
  • Loading branch information
Michal Hecko authored and pirat89 committed Nov 10, 2023
1 parent 64ec2ec commit bbed72d
Show file tree
Hide file tree
Showing 13 changed files with 1,066 additions and 248 deletions.
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

0 comments on commit bbed72d

Please sign in to comment.