Skip to content

Commit c3824c0

Browse files
Michal HeckoPeterMocary
authored andcommitted
rhui: bootstrap target rhui clients in scratch container
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
1 parent d74ff90 commit c3824c0

File tree

13 files changed

+1066
-248
lines changed

13 files changed

+1066
-248
lines changed

repos/system_upgrade/common/actors/checketcreleasever/tests/test_checketcreleasever.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
from leapp import reporting
66
from leapp.libraries.actor import checketcreleasever
7-
from leapp.libraries.common.testutils import (
8-
create_report_mocked,
9-
CurrentActorMocked,
10-
logger_mocked
11-
)
7+
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked, logger_mocked
128
from leapp.libraries.stdlib import api
13-
from leapp.models import PkgManagerInfo, Report, RHUIInfo
9+
from leapp.models import (
10+
PkgManagerInfo,
11+
Report,
12+
RHUIInfo,
13+
TargetRHUIPostInstallTasks,
14+
TargetRHUIPreInstallTasks,
15+
TargetRHUISetupInfo
16+
)
1417

1518

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

5760

61+
def mk_rhui_info():
62+
preinstall_tasks = TargetRHUIPreInstallTasks()
63+
postinstall_tasks = TargetRHUIPostInstallTasks()
64+
setup_info = TargetRHUISetupInfo(preinstall_tasks=preinstall_tasks, postinstall_tasks=postinstall_tasks)
65+
rhui_info = RHUIInfo(provider='aws',
66+
src_client_pkg_names=['rh-amazon-rhui-client'],
67+
target_client_pkg_names=['rh-amazon-rhui-client'],
68+
target_client_setup_info=setup_info)
69+
return rhui_info
70+
71+
5872
@pytest.mark.parametrize('is_rhui', [True, False])
5973
def test_etc_releasever_rhui(monkeypatch, is_rhui):
60-
rhui_msg = [RHUIInfo(provider='aws')] if is_rhui else []
74+
if is_rhui:
75+
rhui_msg = [mk_rhui_info()]
76+
else:
77+
rhui_msg = []
78+
6179
expected_rel_ver = '6.10'
6280

6381
mocked_report = create_report_mocked()
@@ -92,7 +110,9 @@ def test_etc_releasever_neither(monkeypatch):
92110

93111

94112
def test_etc_releasever_both(monkeypatch):
95-
msgs = [RHUIInfo(provider='aws'), PkgManagerInfo(etc_releasever='7.7')]
113+
rhui_info = mk_rhui_info()
114+
115+
msgs = [rhui_info, PkgManagerInfo(etc_releasever='7.7')]
96116
expected_rel_ver = '6.10'
97117

98118
mocked_report = create_report_mocked()

repos/system_upgrade/common/actors/cloud/checkhybridimage/libraries/checkhybridimage.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from leapp import reporting
44
from leapp.libraries.common import rhui
5+
from leapp.libraries.common.config.version import get_source_major_version
56
from leapp.libraries.common.rpms import has_package
67
from leapp.libraries.stdlib import api
78
from leapp.models import FirmwareFacts, HybridImage, InstalledRPM
@@ -20,8 +21,20 @@ def is_grubenv_symlink_to_efi():
2021

2122
def is_azure_agent_installed():
2223
"""Check whether 'WALinuxAgent' package is installed."""
23-
upg_path = rhui.get_upg_path()
24-
agent_pkg = rhui.RHUI_CLOUD_MAP[upg_path].get('azure', {}).get('agent_pkg', '')
24+
src_ver_major = get_source_major_version()
25+
26+
family = rhui.RHUIFamily(rhui.RHUIProvider.AZURE)
27+
azure_setups = rhui.RHUI_SETUPS.get(family, [])
28+
29+
agent_pkg = None
30+
for setup in azure_setups:
31+
if setup.os_version == src_ver_major:
32+
agent_pkg = setup.extra_info.get('agent_pkg')
33+
break
34+
35+
if not agent_pkg:
36+
return False
37+
2538
return has_package(InstalledRPM, agent_pkg)
2639

2740

Lines changed: 3 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import os
2-
3-
from leapp import reporting
41
from leapp.actors import Actor
5-
from leapp.libraries.common import rhsm, rhui
6-
from leapp.libraries.common.config.version import get_source_major_version
7-
from leapp.libraries.common.rpms import has_package
8-
from leapp.libraries.stdlib import api
2+
from leapp.libraries.actor import checkrhui as checkrhui_lib
93
from leapp.models import (
104
CopyFile,
115
DNFPluginTask,
@@ -16,7 +10,7 @@
1610
RpmTransactionTasks,
1711
TargetUserSpacePreupgradeTasks
1812
)
19-
from leapp.reporting import create_report, Report
13+
from leapp.reporting import Report
2014
from leapp.tags import FactsPhaseTag, IPUWorkflowTag
2115

2216

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

4236
def process(self):
43-
upg_path = rhui.get_upg_path()
44-
for provider, info in rhui.RHUI_CLOUD_MAP[upg_path].items():
45-
if has_package(InstalledRPM, info['src_pkg']):
46-
# we need to do this workaround in order to overcome our RHUI handling limitation
47-
# in case there are more client packages on the source system
48-
# @Note(mhecko): Azure has changed the structure of their images to not use a pair of RHUI clients and
49-
# # instead they started to use a single package. However, it could happen that a user
50-
# # does not run `dnf upgrade` and thus has both packages installed.
51-
if 'azure' in info['src_pkg']:
52-
azure_sap_variants = ['azure-sap-ha', 'azure-sap-apps']
53-
for azure_sap_variant in azure_sap_variants:
54-
sap_variant_info = rhui.RHUI_CLOUD_MAP[upg_path][azure_sap_variant]
55-
if has_package(InstalledRPM, sap_variant_info['src_pkg']):
56-
info = sap_variant_info
57-
provider = azure_sap_variant
58-
59-
if provider.startswith('google'):
60-
rhui_dir = api.get_common_folder_path('rhui')
61-
repofile = os.path.join(rhui_dir, provider, 'leapp-{}.repo'.format(provider))
62-
api.produce(
63-
TargetUserSpacePreupgradeTasks(
64-
copy_files=[CopyFile(src=repofile, dst='/etc/yum.repos.d/leapp-google-copied.repo')]
65-
)
66-
)
67-
68-
if not rhsm.skip_rhsm():
69-
create_report([
70-
reporting.Title('Upgrade initiated with RHSM on public cloud with RHUI infrastructure'),
71-
reporting.Summary(
72-
'Leapp detected this system is on public cloud with RHUI infrastructure '
73-
'but the process was initiated without "--no-rhsm" command line option '
74-
'which implies RHSM usage (valid subscription is needed).'
75-
),
76-
reporting.Severity(reporting.Severity.INFO),
77-
reporting.Groups([reporting.Groups.PUBLIC_CLOUD]),
78-
])
79-
return
80-
81-
# When upgrading with RHUI we cannot switch certs and let RHSM provide us repos for target OS content.
82-
# Instead, Leapp's provider-specific package containing target OS certs and repos has to be installed.
83-
if not has_package(InstalledRPM, info['leapp_pkg']):
84-
create_report([
85-
reporting.Title('Package "{}" is missing'.format(info['leapp_pkg'])),
86-
reporting.Summary(
87-
'On {} using RHUI infrastructure, a package "{}" is needed for '
88-
'in-place upgrade'.format(provider.upper(), info['leapp_pkg'])
89-
),
90-
reporting.Severity(reporting.Severity.HIGH),
91-
reporting.RelatedResource('package', info['leapp_pkg']),
92-
reporting.Groups([reporting.Groups.INHIBITOR]),
93-
reporting.Groups([reporting.Groups.PUBLIC_CLOUD, reporting.Groups.RHUI]),
94-
reporting.Remediation(commands=[['yum', 'install', '-y', info['leapp_pkg']]])
95-
])
96-
return
97-
98-
# there are several "variants" related to the *AWS* provider (aws, aws-sap)
99-
if provider.startswith('aws'):
100-
# We have to disable Amazon-id plugin in the initramdisk phase as the network
101-
# is down at the time
102-
self.produce(DNFPluginTask(name='amazon-id', disable_in=['upgrade']))
103-
104-
# If source OS and target OS packages differ we must remove the source pkg, and install the target pkg.
105-
# If the packages do not differ, it is sufficient to upgrade them during the upgrade
106-
if info['src_pkg'] != info['target_pkg']:
107-
self.produce(RpmTransactionTasks(to_install=[info['target_pkg']]))
108-
self.produce(RpmTransactionTasks(to_remove=[info['src_pkg']]))
109-
110-
# Although SAP systems on Azure should not rely on a pair of RHUI clients, it is still possible
111-
# that the source system has both clients installed, and it is safer to remove both of them.
112-
azure_nonsap_pkg = None
113-
if provider == 'azure-sap-ha':
114-
azure_nonsap_pkg = rhui.RHUI_CLOUD_MAP[upg_path]['azure']['src_pkg']
115-
elif provider == 'azure-sap-apps':
116-
# SAP Apps systems have EUS content channel from RHEL8+
117-
src_rhel_content_type = 'azure' if get_source_major_version() == '7' else 'azure-eus'
118-
azure_nonsap_pkg = rhui.RHUI_CLOUD_MAP[upg_path][src_rhel_content_type]['src_pkg']
119-
if azure_nonsap_pkg and has_package(InstalledRPM, azure_nonsap_pkg):
120-
self.produce(RpmTransactionTasks(to_remove=[azure_nonsap_pkg]))
121-
122-
self.produce(RHUIInfo(provider=provider))
123-
self.produce(RequiredTargetUserspacePackages(packages=[info['target_pkg']]))
124-
return
37+
checkrhui_lib.process()

0 commit comments

Comments
 (0)