Skip to content

Commit 500967b

Browse files
committed
upgrade data files loading: update error msgs and repors + minor changes
Updated number of error messages and reports to be sure that users know what files are actually problematic. Original errors and reports usually didn't contain the full path to an upgrade data file due to possibility to download the file from a server. However, the posibility to download fresh data files from a requested server is not expected to support in the current state as the data files are part of provided packages. I've been thinking quite long time whether to actually drop or deprecate bigger part of the code to simplify the whole solution, as currently it's not planned to have a possibility to download some data files from servers in future. However, thinking about upcoming challenges, I am not totally persuaded that we will not revive that functionality in future, or that we will not want to use it for something little bit different. From that POV (and late phase of development prior the planned release) I think it will be better to preserve it for now and raise a discussion about it later. Other changes in this PR: * drop hardcoded name of the leapp-upgrade-elXtoelY rpm and use the leapp.libraries.common.rpms.get_leapp_packages() function * replace REPOSITORY group by SANITY; it was originally a mixture of both and SANITY fits better to me from this point * the check of consumed data sets could produce report with empty links, as the original article(s) we referred to have been obsoleted; so added filter for missing URLs
1 parent b5d2673 commit 500967b

File tree

5 files changed

+73
-30
lines changed

5 files changed

+73
-30
lines changed

repos/system_upgrade/common/actors/checkconsumedassets/libraries/check_consumed_assets.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,27 @@
44
from leapp import reporting
55
from leapp.libraries.common.config import get_consumed_data_stream_id
66
from leapp.libraries.common.fetch import ASSET_PROVIDED_DATA_STREAMS_FIELD
7+
from leapp.libraries.common.rpms import get_leapp_packages, LeappComponents
78
from leapp.libraries.stdlib import api
89
from leapp.models import ConsumedDataAsset
910

1011

12+
def _get_hint():
13+
hint = (
14+
'All official assets (data files) are nowadays part of the installed rpms.'
15+
' This issue is usually encountered when the data files are incorrectly'
16+
' customized, replaced, or removed. '
17+
' In case you want to recover original files, remove them (if still exist)'
18+
' and reinstall following rpms: {rpms}.\n'
19+
'The listed assets (data files) are usually inside the /etc/leapp/files/'
20+
' directory.'
21+
.format(
22+
rpms=', '.join(get_leapp_packages(component=LeappComponents.REPOSITORY))
23+
)
24+
)
25+
return hint
26+
27+
1128
def compose_summary_for_incompatible_assets(assets, incompatibility_reason):
1229
if not assets:
1330
return []
@@ -69,13 +86,16 @@ def report_incompatible_assets(assets):
6986
summary_lines += compose_summary_for_incompatible_assets(incompatible_assets, reason)
7087

7188
for asset in incompatible_assets:
72-
doc_url_to_title[asset.docs_url].append(asset.docs_title)
89+
if asset.docs_url:
90+
# Add URLs only when they are specified. docs_url could be empty string
91+
doc_url_to_title[asset.docs_url].append(asset.docs_title)
7392

7493
report_parts = [
7594
reporting.Title(title),
7695
reporting.Summary('\n'.join(summary_lines)),
7796
reporting.Severity(reporting.Severity.HIGH),
78-
reporting.Groups([reporting.Groups.INHIBITOR, reporting.Groups.REPOSITORY]),
97+
reporting.Remediation(hint=_get_hint()),
98+
reporting.Groups([reporting.Groups.INHIBITOR, reporting.Groups.SANITY]),
7999
]
80100

81101
report_parts += make_report_entries_with_unique_urls(docs_url_to_title_map)
@@ -101,13 +121,16 @@ def report_malformed_assets(malformed_assets):
101121
details = ' - The asset file {filename} contains invalid value in its "{data_streams_field}"'
102122
details = details.format(filename=asset.filename, data_streams_field=ASSET_PROVIDED_DATA_STREAMS_FIELD)
103123
summary_lines.append(details)
104-
docs_url_to_title_map[asset.docs_url].append(asset.docs_title)
124+
if asset.docs_url:
125+
# Add URLs only when they are specified. docs_url could be empty string
126+
docs_url_to_title_map[asset.docs_url].append(asset.docs_title)
105127

106128
report_parts = [
107129
reporting.Title(title),
108130
reporting.Summary('\n'.join(summary_lines)),
131+
reporting.Remediation(hint=_get_hint()),
109132
reporting.Severity(reporting.Severity.HIGH),
110-
reporting.Groups([reporting.Groups.INHIBITOR, reporting.Groups.REPOSITORY]),
133+
reporting.Groups([reporting.Groups.INHIBITOR, reporting.Groups.SANITY]),
111134
]
112135

113136
report_parts += make_report_entries_with_unique_urls(docs_url_to_title_map)

repos/system_upgrade/common/actors/loaddevicedriverdeprecationdata/libraries/deviceanddriverdeprecationdataload.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def process():
1313
supported_device_types = set(DeviceDriverDeprecationEntry.device_type.serialize()['choices'])
1414

1515
data_file_name = 'device_driver_deprecation_data.json'
16+
# NOTE(pstodulk): load_data_assert raises StopActorExecutionError, see
17+
# the code for more info. Keeping the handling on the framework in such
18+
# a case as we have no work to do in such a case here.
1619
deprecation_data = fetch.load_data_asset(api.current_actor(),
1720
data_file_name,
1821
asset_fulltext_name='Device driver deprecation data',

repos/system_upgrade/common/actors/peseventsscanner/libraries/pes_event_parsing.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from leapp.exceptions import StopActorExecution
99
from leapp.libraries.common import fetch
1010
from leapp.libraries.common.config import architecture
11-
from leapp.libraries.common.config.version import get_source_major_version, get_target_major_version
11+
from leapp.libraries.common.rpms import get_leapp_packages, LeappComponents
1212
from leapp.libraries.stdlib import api
1313

1414
# NOTE(mhecko): The modulestream field contains a set of modulestreams until the very end when we generate a Package
@@ -67,6 +67,9 @@ def get_pes_events(pes_json_directory, pes_json_filename):
6767
:return: List of Event tuples, where each event contains event type and input/output pkgs
6868
"""
6969
try:
70+
# NOTE(pstodulk): load_data_assert raises StopActorExecutionError, see
71+
# the code for more info. Keeping the handling on the framework in such
72+
# a case as we have no work to do in such a case here.
7073
events_data = fetch.load_data_asset(api.current_actor(),
7174
pes_json_filename,
7275
asset_fulltext_name='PES events file',
@@ -83,22 +86,27 @@ def get_pes_events(pes_json_directory, pes_json_filename):
8386
events_matching_arch = [e for e in all_events if not e.architectures or arch in e.architectures]
8487
return events_matching_arch
8588
except (ValueError, KeyError):
86-
rpmname = 'leapp-upgrade-el{}toel{}'.format(get_source_major_version(), get_target_major_version())
87-
title = 'Missing/Invalid PES data file ({}/{})'.format(pes_json_directory, pes_json_filename)
89+
local_path = os.path.join(pes_json_directory, pes_json_filename)
90+
title = 'Missing/Invalid PES data file ({})'.format(local_path)
8891
summary = (
8992
'All official data files are nowadays part of the installed rpms.'
9093
' This issue is usually encountered when the data files are incorrectly customized, replaced, or removed'
9194
' (e.g. by custom scripts).'
92-
' In case you want to recover the original file, remove it (if still exists)'
93-
' and reinstall the {} rpm.'
94-
.format(rpmname)
95+
)
96+
hint = (
97+
' In case you want to recover the original {lp} file, remove it (if still exists)'
98+
' and reinstall following rpms: {rpms}.'
99+
.format(
100+
lp=local_path,
101+
rpms=', '.join(get_leapp_packages(component=LeappComponents.REPOSITORY))
102+
)
95103
)
96104
reporting.create_report([
97105
reporting.Title(title),
98106
reporting.Summary(summary),
107+
reporting.Remediation(hint=hint),
99108
reporting.Severity(reporting.Severity.HIGH),
100-
reporting.Groups([reporting.Groups.SANITY]),
101-
reporting.Groups([reporting.Groups.INHIBITOR]),
109+
reporting.Groups([reporting.Groups.SANITY, reporting.Groups.INHIBITOR]),
102110
reporting.RelatedResource('file', os.path.join(pes_json_directory, pes_json_filename))
103111
])
104112
raise StopActorExecution()

repos/system_upgrade/common/actors/repositoriesmapping/libraries/repositoriesmapping.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from leapp.exceptions import StopActorExecutionError
55
from leapp.libraries.common.config.version import get_source_major_version, get_target_major_version
66
from leapp.libraries.common.fetch import load_data_asset
7+
from leapp.libraries.common.rpms import get_leapp_packages, LeappComponents
78
from leapp.libraries.stdlib import api
89
from leapp.models import PESIDRepositoryEntry, RepoMapEntry, RepositoriesMapping
910
from leapp.models.fields import ModelViolationError
@@ -130,29 +131,31 @@ def load_from_dict(data):
130131

131132

132133
def _inhibit_upgrade(msg):
133-
rpmname = 'leapp-upgrade-el{}toel{}'.format(get_source_major_version(), get_target_major_version())
134+
local_path = os.path.join('/etc/leapp/file', REPOMAP_FILE)
134135
hint = (
135136
'All official data files are nowadays part of the installed rpms.'
136137
' This issue is usually encountered when the data files are incorrectly customized, replaced, or removed'
137138
' (e.g. by custom scripts).'
138-
' In case you want to recover the original file, remove it (if still exists)'
139-
' and reinstall the {} rpm.'
140-
.format(rpmname)
139+
' In case you want to recover the original {lp} file, remove the current one (if still exists)'
140+
' and reinstall following packages: {rpms}.'
141+
.format(
142+
lp=local_path,
143+
rpms=', '.join(get_leapp_packages(component=LeappComponents.REPOSITORY))
144+
)
141145
)
142146
raise StopActorExecutionError(msg, details={'hint': hint})
143147

144148

145149
def _read_repofile(repofile):
146-
# NOTE: what about catch StopActorExecution error when the file cannot be
147-
# obtained -> then check whether old_repomap file exists and in such a case
148-
# inform user they have to provide the new repomap.json file (we have the
149-
# warning now only which could be potentially overlooked)
150+
# NOTE(pstodulk): load_data_assert raises StopActorExecutionError, see
151+
# the code for more info. Keeping the handling on the framework in such
152+
# a case as we have no work to do in such a case here.
150153
repofile_data = load_data_asset(api.current_actor(),
151154
repofile,
152155
asset_fulltext_name='Repositories mapping',
153156
docs_url='',
154157
docs_title='')
155-
return repofile_data # If the file does not contain a valid json then load_asset will do a stop actor execution
158+
return repofile_data
156159

157160

158161
def scan_repositories(read_repofile_func=_read_repofile):

repos/system_upgrade/common/libraries/fetch.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from leapp import models
88
from leapp.exceptions import StopActorExecutionError
99
from leapp.libraries.common.config import get_consumed_data_stream_id, get_env
10-
from leapp.libraries.common.config.version import get_source_major_version, get_target_major_version
10+
from leapp.libraries.common.rpms import get_leapp_packages, LeappComponents
1111
from leapp.libraries.stdlib import api
1212

1313
SERVICE_HOST_DEFAULT = "https://cert.cloud.redhat.com"
@@ -16,16 +16,18 @@
1616
ASSET_PROVIDED_DATA_STREAMS_FIELD = 'provided_data_streams'
1717

1818

19-
def _get_hint():
20-
rpmname = 'leapp-upgrade-el{}toel{}'.format(get_source_major_version(), get_target_major_version())
19+
def _get_hint(local_path):
2120
hint = (
2221
'All official data files are nowadays part of the installed rpms.'
2322
' That is the only official resource of actual official data files for in-place upgrades.'
2423
' This issue is usually encountered when the data files are incorrectly customized, replaced, or removed'
2524
' (e.g. by custom scripts).'
26-
' In case you want to recover the original file, remove it (if still exists)'
27-
' and reinstall the {} rpm.'
28-
.format(rpmname)
25+
' In case you want to recover the original {lp} file, remove the current one (if still exists)'
26+
' and reinstall following packages: {rpms}.'
27+
.format(
28+
lp=local_path,
29+
rpms=', '.join(get_leapp_packages(component=LeappComponents.REPOSITORY))
30+
)
2931
)
3032
return hint
3133

@@ -34,10 +36,9 @@ def _raise_error(local_path, details):
3436
"""
3537
If the file acquisition fails in any way, throw an informative error to stop the actor.
3638
"""
37-
rpmname = 'leapp-upgrade-el{}toel{}'.format(get_source_major_version(), get_target_major_version())
3839
summary = 'Data file {lp} is missing or invalid.'.format(lp=local_path)
3940

40-
raise StopActorExecutionError(summary, details={'details': details, 'hint': _get_hint()})
41+
raise StopActorExecutionError(summary, details={'details': details, 'hint': _get_hint(local_path)})
4142

4243

4344
def _request_data(service_path, cert, proxies, timeout=REQUEST_TIMEOUT):
@@ -148,6 +149,7 @@ def load_data_asset(actor_requesting_asset,
148149
docs_title):
149150
"""
150151
Load the content of the data asset with given asset_filename
152+
and produce :class:`leapp.model.ConsumedDataAsset` message.
151153
152154
:param Actor actor_requesting_asset: The actor instance requesting the asset file. It is necessary for the actor
153155
to be able to produce ConsumedDataAsset message in order for leapp to be able
@@ -157,6 +159,10 @@ def load_data_asset(actor_requesting_asset,
157159
:param str docs_url: Docs url to provide if an asset is malformed or outdated.
158160
:param str docs_title: Title of the documentation to where `docs_url` points to.
159161
:returns: A dict with asset contents (a parsed JSON), or None if the asset was outdated.
162+
:raises StopActorExecutionError: In following cases:
163+
* ConsumedDataAsset is not specified in the produces tuple of the actor_requesting_asset actor
164+
* The content of the required data file is not valid JSON format
165+
* The required data cannot be obtained (e.g. due to missing file)
160166
"""
161167

162168
# Check that the actor that is attempting to obtain the asset meets the contract to call this function
@@ -167,7 +173,7 @@ def load_data_asset(actor_requesting_asset,
167173
error_hint = {'hint': ('Read documentation at the following link for more information about how to retrieve '
168174
'the valid file: {0}'.format(docs_url))}
169175
else:
170-
error_hint = {'hint': _get_hint()}
176+
error_hint = {'hint': _get_hint(os.path.join('/etc/leapp/files', asset_filename))}
171177

172178
data_stream_id = get_consumed_data_stream_id()
173179
data_stream_major = data_stream_id.split('.', 1)[0]

0 commit comments

Comments
 (0)