Skip to content

Commit 25b2e2f

Browse files
author
mhecko
committed
rhui: add granularity to cleanup prevention
1 parent b9deee8 commit 25b2e2f

File tree

8 files changed

+74
-77
lines changed

8 files changed

+74
-77
lines changed

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

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
from leapp.libraries.actor import checketcreleasever
77
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked, logger_mocked
88
from leapp.libraries.stdlib import api
9-
from leapp.models import PkgManagerInfo, Report, RHUIInfo, TargetRHUISetupInfo
9+
from leapp.models import (
10+
PkgManagerInfo,
11+
Report,
12+
RHUIInfo,
13+
TargetRHUIPostInstallTasks,
14+
TargetRHUIPreInstallTasks,
15+
TargetRHUISetupInfo
16+
)
1017

1118

1219
@pytest.mark.parametrize('exists', [True, False])
@@ -51,14 +58,21 @@ def test_etc_releasever_empty(monkeypatch):
5158
assert api.current_logger.dbgmsg
5259

5360

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+
5472
@pytest.mark.parametrize('is_rhui', [True, False])
5573
def test_etc_releasever_rhui(monkeypatch, is_rhui):
5674
if is_rhui:
57-
rhui_info = RHUIInfo(provider='aws',
58-
src_client_pkg_names=['rh-amazon-rhui-client'],
59-
target_client_pkg_names=['rh-amazon-rhui-client'],
60-
target_client_setup_info=TargetRHUISetupInfo())
61-
rhui_msg = [rhui_info]
75+
rhui_msg = [mk_rhui_info()]
6276
else:
6377
rhui_msg = []
6478

@@ -96,10 +110,7 @@ def test_etc_releasever_neither(monkeypatch):
96110

97111

98112
def test_etc_releasever_both(monkeypatch):
99-
rhui_info = RHUIInfo(provider='aws',
100-
src_client_pkg_names=['rh-amazon-rhui-client'],
101-
target_client_pkg_names=['rh-amazon-rhui-client'],
102-
target_client_setup_info=TargetRHUISetupInfo())
113+
rhui_info = mk_rhui_info()
103114

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def is_azure_agent_installed():
2727
agent_pkg = None
2828
for setup in azure_setups:
2929
if setup.os_version == src_ver_major:
30-
agent_pkg = setup.extra_info.get('agent-pkg')
30+
agent_pkg = setup.extra_info.get('agent_pkg')
31+
break;
3132

3233
if not agent_pkg:
3334
return False

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
TargetUserSpacePreupgradeTasks
2020
)
2121

22-
2322
MatchingSetup = namedtuple('MatchingSetup', ['name', 'description'])
2423

2524

@@ -104,29 +103,13 @@ def stop_due_to_unknown_target_system_setup(variant):
104103
raise StopActorExecutionError(message=msg, details={'details': details})
105104

106105

107-
def customize_rhui_setup_for_aws(provider, setup_info):
108-
if not provider.startswith('aws'):
109-
return
110-
111-
target_version = version.get_target_major_version()
112-
if target_version == '8':
113-
amazon_plugin_copy_task = CopyFile(src='/usr/lib/python3.6/site-packages/dnf-plugins/amazon-id.py',
114-
dst='/usr/lib/python2.7/site-packages/dnf-plugins/')
115-
else:
116-
amazon_plugin_copy_task = CopyFile(src='/usr/lib/python3.9/site-packages/dnf-plugins/amazon-id.py',
117-
dst='/usr/lib/python3.6/site-packages/dnf-plugins/')
118-
119-
setup_info.postinstall_tasks.files_to_copy.append(amazon_plugin_copy_task)
120-
121-
122106
def customize_rhui_setup_for_gcp(provider, setup_info):
123107
if not provider.startswith('google'):
124108
return
125109

126110
# The google-cloud.repo repofile provides the repoid with target clients, however, the repoid is the same across
127111
# all rhel versions, therefore, we need to remove the source google-cloud.repo to enable correct target one.
128112
setup_info.preinstall_tasks.files_to_remove.append('/etc/yum.repos.d/google-cloud.repo')
129-
setup_info.are_clients_sufficient = False
130113

131114

132115
def produce_rhui_info_to_setup_target(variant, source_setup_desc, target_setup_desc):
@@ -147,19 +130,23 @@ def produce_rhui_info_to_setup_target(variant, source_setup_desc, target_setup_d
147130

148131
preinstall_tasks = TargetRHUIPreInstallTasks(files_to_copy_in=files_to_access_target_client_repo)
149132

133+
files_supporting_client_operation = sorted(
134+
os.path.join(rhui_files_location, file) for file in target_setup_desc.files_supporting_client_operation
135+
)
136+
150137
target_client_setup_info = TargetRHUISetupInfo(
151138
preinstall_tasks=preinstall_tasks,
152139
postinstall_tasks=TargetRHUIPostInstallTasks(),
140+
files_supporting_client_operation=files_supporting_client_operation
153141
)
154142

155-
customize_rhui_setup_for_aws(variant, target_client_setup_info)
156143
customize_rhui_setup_for_gcp(variant, target_client_setup_info)
157144

158145
rhui_info = RHUIInfo(
159146
provider=variant,
160147
src_client_pkg_names=sorted(source_setup_desc.clients),
161148
target_client_pkg_names=sorted(target_setup_desc.clients),
162-
target_client_setup_info=target_client_setup_info,
149+
target_client_setup_info=target_client_setup_info
163150
)
164151
api.produce(rhui_info)
165152

repos/system_upgrade/common/actors/cloud/checkrhui/tests/component_test_checkrhui.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from leapp.libraries.actor import checkrhui as checkrhui_lib
99
from leapp.libraries.common import rhsm, rhui
1010
from leapp.libraries.common.config import mock_configs, version
11-
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked, produce_mocked
1211
from leapp.libraries.common.rhui import mk_rhui_setup
12+
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked, produce_mocked
1313
from leapp.libraries.stdlib import api
1414
from leapp.models import (
1515
CopyFile,
@@ -123,34 +123,13 @@ def test_inhibit_on_missing_leapp_rhui_pkg(monkeypatch, extra_pkgs, target_rhui_
123123
def are_setup_infos_eq(actual, expected):
124124
eq = True
125125
eq &= actual.enable_only_repoids_in_copied_files == expected.enable_only_repoids_in_copied_files
126-
eq &= actual.are_clients_sufficient == expected.are_clients_sufficient
126+
eq &= actual.files_supporting_client_operation == expected.files_supporting_client_operation
127127
eq &= actual.preinstall_tasks.files_to_remove == expected.preinstall_tasks.files_to_remove
128128
eq &= actual.preinstall_tasks.files_to_copy_in == expected.preinstall_tasks.files_to_copy_in
129129
eq &= actual.postinstall_tasks.files_to_copy == expected.postinstall_tasks.files_to_copy
130130
return eq
131131

132132

133-
@pytest.mark.parametrize(
134-
('provider', 'target_major', 'should_mutate'),
135-
[
136-
('aws', '7', True),
137-
('aws', '8', True),
138-
('aws-sap-e4s', '8', True),
139-
('azure-sap-apps', '8', False),
140-
]
141-
)
142-
def test_aws_specific_customization(monkeypatch, provider, target_major, should_mutate):
143-
monkeypatch.setattr(version, 'get_target_major_version', lambda: target_major)
144-
145-
setup_info = mk_setup_info()
146-
checkrhui_lib.customize_rhui_setup_for_aws(provider, setup_info)
147-
148-
if should_mutate:
149-
assert not are_setup_infos_eq(setup_info, mk_setup_info())
150-
else:
151-
assert are_setup_infos_eq(setup_info, mk_setup_info())
152-
153-
154133
@pytest.mark.parametrize(
155134
('provider', 'should_mutate'),
156135
[

repos/system_upgrade/common/actors/setetcreleasever/tests/test_setetcreleasever.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
from leapp.libraries.actor import setetcreleasever
66
from leapp.libraries.common.testutils import create_report_mocked, CurrentActorMocked, logger_mocked
77
from leapp.libraries.stdlib import api
8-
from leapp.models import PkgManagerInfo, RHUIInfo, TargetRHUISetupInfo
8+
from leapp.models import (
9+
PkgManagerInfo,
10+
RHUIInfo,
11+
TargetRHUIPostInstallTasks,
12+
TargetRHUIPreInstallTasks,
13+
TargetRHUISetupInfo
14+
)
915

1016
CUR_DIR = os.path.dirname(os.path.abspath(__file__))
1117

@@ -29,10 +35,14 @@ def __call__(self, content):
2935

3036

3137
def test_set_releasever(monkeypatch, current_actor_context):
38+
preinstall_tasks = TargetRHUIPreInstallTasks()
39+
postinstall_tasks = TargetRHUIPostInstallTasks()
40+
setup_info = TargetRHUISetupInfo(preinstall_tasks=preinstall_tasks, postinstall_tasks=postinstall_tasks)
3241
rhui_info = RHUIInfo(provider='aws',
3342
src_client_pkg_names=['rh-amazon-rhui-client'],
3443
target_client_pkg_names=['rh-amazon-rhui-client'],
35-
target_client_setup_info=TargetRHUISetupInfo())
44+
target_client_setup_info=setup_info)
45+
3646
msgs = [rhui_info, PkgManagerInfo(etc_releasever='7.7')]
3747

3848
expected_rel_ver = '8.0'

repos/system_upgrade/common/actors/targetuserspacecreator/libraries/userspacegen.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ def is_repofile(path):
579579
return os.path.dirname(path) == '/etc/yum.repos.d' and os.path.basename(path).endswith('.repo')
580580

581581
def extract_repoid_from_line(line):
582-
return line.split(':', maxsplit=1)[1].strip()
582+
return line.split(':', 1)[1].strip()
583583

584584
target_ver = api.current_actor().configuration.version.target
585585
setup_tasks = indata.rhui_info.target_client_setup_info.preinstall_tasks.files_to_copy_in
@@ -819,7 +819,6 @@ def install_target_rhui_client_if_needed(context, indata):
819819
context.makedirs(os.path.dirname(copy_info.dst), exists_ok=True)
820820
context.copy_to(copy_info.src, copy_info.dst)
821821

822-
# @Todo: We might need to handle GPG stuff here in order to install the client
823822
cmd = ['dnf', '-y']
824823

825824
if setup_info.enable_only_repoids_in_copied_files and setup_info.preinstall_tasks:
@@ -854,15 +853,14 @@ def install_target_rhui_client_if_needed(context, indata):
854853
context.makedirs(os.path.dirname(copy_info.dst), exists_ok=True)
855854
context.call(['cp', copy_info.src, copy_info.dst])
856855

857-
# If the clients are sufficient to access target RHUI then remove copied repofiles so that
858-
# there are no duplicit repoids
859-
if setup_info.are_clients_sufficient:
860-
files_owned_by_clients = _query_rpm_for_pkg_files(context, indata.rhui_info.target_client_pkg_names)
856+
# Do a cleanup so there are not duplicit repoids
857+
files_owned_by_clients = _query_rpm_for_pkg_files(context, indata.rhui_info.target_client_pkg_names)
861858

862-
for copy_task in setup_info.preinstall_tasks.files_to_copy_in:
863-
dest = get_copy_location_from_copy_in_task(context, copy_task)
864-
if dest not in files_owned_by_clients:
865-
context.remove(dest)
859+
for copy_task in setup_info.preinstall_tasks.files_to_copy_in:
860+
dest = get_copy_location_from_copy_in_task(context, copy_task)
861+
can_be_cleaned_up = copy_task.src not in setup_info.files_supporting_client_operation
862+
if dest not in files_owned_by_clients and can_be_cleaned_up:
863+
context.remove(dest)
866864

867865

868866
@suppress_deprecation(TMPTargetRepositoriesFacts)

repos/system_upgrade/common/libraries/rhui.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1+
import os
12
from collections import namedtuple
23
from enum import Enum
3-
import os
44

55
import six
66

77
from leapp.libraries.common.config import architecture as arch
8-
from leapp.libraries.common.config.version import (
9-
get_source_major_version,
10-
get_target_major_version
11-
)
8+
from leapp.libraries.common.config.version import get_source_major_version, get_target_major_version
129
from leapp.libraries.stdlib import api
1310
from leapp.utils.deprecation import deprecated
1411

@@ -40,7 +37,7 @@ class ContentChannel(Enum):
4037
RHUISetup = namedtuple(
4138
'RHUISetup',
4239
('clients', 'leapp_pkg', 'mandatory_files', 'optional_files', 'extra_info', 'os_version',
43-
'arch', 'content_channel')
40+
'arch', 'content_channel', 'files_supporting_client_operation')
4441
)
4542
"""Information about RHUI setups used during IPU
4643
.. py:attribute:: clients
@@ -61,23 +58,27 @@ class ContentChannel(Enum):
6158
Instruction set of the RHUI system.
6259
.. py:attribute:: content_channel
6360
Content channel used by the RHUI setup.
61+
.. py:attribute:: files_supporting_client_operation
62+
A subset of files from ``mandatory_files`` that are neccessary for client to work (cannot be cleaned up).
6463
"""
6564

6665

6766
def mk_rhui_setup(clients=None, leapp_pkg='', mandatory_files=None, optional_files=None,
68-
extra_info=None, os_version='7', arch=arch.ARCH_X86_64, content_channel=ContentChannel.GA):
67+
extra_info=None, os_version='7', arch=arch.ARCH_X86_64, content_channel=ContentChannel.GA,
68+
files_supporting_client_operation=None):
6969
clients = clients or set()
7070
mandatory_files = mandatory_files or []
7171
extra_info = extra_info or {}
72+
files_supporting_client_operation = files_supporting_client_operation or []
7273

7374
# Since the default optional files are not [], we cannot use the same construction as above
7475
# to allow the caller to specify empty optional files
7576
default_opt_files = [('content.crt', RHUI_PKI_PRODUCT_DIR), ('key.pem', RHUI_PKI_DIR)]
7677
optional_files = default_opt_files if optional_files is None else optional_files
7778

78-
return RHUISetup(clients=clients, leapp_pkg=leapp_pkg, mandatory_files=mandatory_files,
79+
return RHUISetup(clients=clients, leapp_pkg=leapp_pkg, mandatory_files=mandatory_files, arch=arch,
7980
content_channel=content_channel, optional_files=optional_files, extra_info=extra_info,
80-
os_version=os_version, arch=arch)
81+
os_version=os_version, files_supporting_client_operation=files_supporting_client_operation)
8182

8283

8384
# This will be the new "cloud map". Essentially a directed graph with edges defined implicitly by OS versions +
@@ -93,6 +94,7 @@ def mk_rhui_setup(clients=None, leapp_pkg='', mandatory_files=None, optional_fil
9394
(AWS_DNF_PLUGIN_NAME, DNF_PLUGIN_PATH_PY2),
9495
('leapp-aws.repo', YUM_REPOS_PATH)
9596
],
97+
files_supporting_client_operation=[AWS_DNF_PLUGIN_NAME],
9698
optional_files=[], os_version='8'),
9799
mk_rhui_setup(clients={'rh-amazon-rhui-client-arm'}, leapp_pkg='leapp-rhui-aws',
98100
mandatory_files=[
@@ -101,7 +103,11 @@ def mk_rhui_setup(clients=None, leapp_pkg='', mandatory_files=None, optional_fil
101103
(AWS_DNF_PLUGIN_NAME, DNF_PLUGIN_PATH_PY2),
102104
('leapp-aws.repo', YUM_REPOS_PATH)
103105
],
106+
files_supporting_client_operation=[AWS_DNF_PLUGIN_NAME],
104107
optional_files=[], os_version='8', arch=arch.ARCH_ARM64),
108+
# @Note(mhecko): We don't need to deal with AWS_DNF_PLUGIN_NAME here as on rhel8+ there is already dnf
109+
# # that has the plugin installed (we don't need to inject it into scratch container's
110+
# # dnf plugins)
105111
mk_rhui_setup(clients={'rh-amazon-rhui-client'}, leapp_pkg='leapp-rhui-aws',
106112
mandatory_files=[
107113
('rhui-client-config-server-9.crt', RHUI_PKI_PRODUCT_DIR),
@@ -138,7 +144,8 @@ def mk_rhui_setup(clients=None, leapp_pkg='', mandatory_files=None, optional_fil
138144
optional_files=[], os_version='9', content_channel=ContentChannel.E4S),
139145
],
140146
'azure': [
141-
mk_rhui_setup(clients={'rhui-azure-rhel7'}, os_version='7'),
147+
mk_rhui_setup(clients={'rhui-azure-rhel7'}, os_version='7',
148+
extra_info={'agent_pkg': 'WALinuxAgent'}),
142149
mk_rhui_setup(clients={'rhui-azure-rhel8'}, leapp_pkg='leapp-rhui-azure',
143150
mandatory_files=[('leapp-azure.repo', YUM_REPOS_PATH)],
144151
extra_info={'agent_pkg': 'WALinuxAgent'},
@@ -174,18 +181,22 @@ def mk_rhui_setup(clients=None, leapp_pkg='', mandatory_files=None, optional_fil
174181
mk_rhui_setup(clients={'google-rhui-client-rhel7'}, os_version='7'),
175182
mk_rhui_setup(clients={'google-rhui-client-rhel8'}, leapp_pkg='leapp-rhui-google',
176183
mandatory_files=[('leapp-google.repo', YUM_REPOS_PATH)],
184+
files_supporting_client_operation=['leapp-google.repo'],
177185
os_version='8'),
178186
mk_rhui_setup(clients={'google-rhui-client-rhel9'}, leapp_pkg='leapp-rhui-google',
179187
mandatory_files=[('leapp-google.repo', YUM_REPOS_PATH)],
188+
files_supporting_client_operation=['leapp-google.repo'],
180189
os_version='9'),
181190
],
182191
'google-sap': [
183192
mk_rhui_setup(clients={'google-rhui-client-rhel79-sap'}, os_version='7', content_channel=ContentChannel.E4S),
184193
mk_rhui_setup(clients={'google-rhui-client-rhel8-sap'}, leapp_pkg='leapp-rhui-google-sap',
185194
mandatory_files=[('leapp-google-sap.repo', YUM_REPOS_PATH)],
195+
files_supporting_client_operation=['leapp-google-sap.repo'],
186196
os_version='8', content_channel=ContentChannel.E4S),
187197
mk_rhui_setup(clients={'google-rhui-client-rhel9-sap'}, leapp_pkg='leapp-rhui-google-sap',
188198
mandatory_files=[('leapp-google-sap.repo', YUM_REPOS_PATH)],
199+
files_supporting_client_operation=['leapp-google-sap.repo'],
189200
os_version='9', content_channel=ContentChannel.E4S),
190201
],
191202
'alibaba': [

repos/system_upgrade/common/models/rhuiinfo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class TargetRHUISetupInfo(Model):
3333
postinstall_tasks = fields.Model(TargetRHUIPostInstallTasks)
3434
"""Tasks that must be performed after the target client is installed (before any other content is accessed)"""
3535

36-
are_clients_sufficient = fields.Boolean(default=True)
37-
"""True if clients provide everything necessary to access target RHUI content"""
36+
files_supporting_client_operation = fields.List(fields.String(), default=[])
37+
"""A subset of files copied in preinstall tasks that should not be cleaned up."""
3838

3939

4040
class RHUIInfo(Model):

0 commit comments

Comments
 (0)