Skip to content

Commit

Permalink
load data files: update hints in error messages and prepare for the d…
Browse files Browse the repository at this point in the history
…ownload drop

As the leapp upgrade data files are nowadays part of the install rpm,
there is no need to download them anymore. Also, we plan to drop the
service providing the data files online in future.

For that reason, update all texts and related error messages so people
are not instructed to visit obsoleted article and do not try to apply
invalid (obsoleted) data files anymore.

Right now, we are keeping the functionality for the data files download,
but the fetch functino is already updated and prepared to stop trying
to download the files if not present. As we have the functionality
already present, I think we should keep a possibility of the download
for additional custom data files (not provided by us) in custom actors,
but for the official data files we will require them in future to be
present locally only.

NOTE: regarding another planned changes soon, skipping update of
unit-tests

Co-authored-by: Michal Hečko <[email protected]>
  • Loading branch information
pirat89 and MichalHe committed Aug 23, 2023
1 parent 4fc0d0b commit af6d7ef
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ def process():
deprecation_data = fetch.load_data_asset(api.current_actor(),
data_file_name,
asset_fulltext_name='Device driver deprecation data',
docs_url='https://access.redhat.com/articles/3664871',
docs_title=('Leapp utility metadata in-place upgrades of RHEL '
'for disconnected upgrades (including Satellite)'))
docs_url='',
docs_title='')

api.produce(
DeviceDriverDeprecationData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from leapp.exceptions import StopActorExecution
from leapp.libraries.common import fetch
from leapp.libraries.common.config import architecture
from leapp.libraries.common.config.version import get_source_major_version, get_target_major_version
from leapp.libraries.stdlib import api

# NOTE(mhecko): The modulestream field contains a set of modulestreams until the very end when we generate a Package
Expand Down Expand Up @@ -69,9 +70,8 @@ def get_pes_events(pes_json_directory, pes_json_filename):
events_data = fetch.load_data_asset(api.current_actor(),
pes_json_filename,
asset_fulltext_name='PES events file',
docs_url='https://access.redhat.com/articles/3664871',
docs_title=('Leapp utility metadata in-place upgrades of RHEL '
'for disconnected upgrades (including Satellite)'))
docs_url='',
docs_title='')
if not events_data:
return None

Expand All @@ -83,9 +83,16 @@ def get_pes_events(pes_json_directory, pes_json_filename):
events_matching_arch = [e for e in all_events if not e.architectures or arch in e.architectures]
return events_matching_arch
except (ValueError, KeyError):
rpmname = 'leapp-upgrade-el{}toel{}'.format(get_source_major_version(), get_target_major_version())
title = 'Missing/Invalid PES data file ({}/{})'.format(pes_json_directory, pes_json_filename)
summary = ('Read documentation at: https://access.redhat.com/articles/3664871 for more information '
'about how to retrieve the files')
summary = (
'All official data files are nowadays part of the installed rpms.'
' This issue is usually encountered when the data files are incorrectly customized, replaced, or removed'
' (e.g. by custom scripts).'
' In case you want to recover the original file, remove it (if still exists)'
' and reinstall the {} rpm.'
.format(rpmname)
)
reporting.create_report([
reporting.Title(title),
reporting.Summary(summary),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,16 @@ def load_from_dict(data):


def _inhibit_upgrade(msg):
raise StopActorExecutionError(
msg,
details={'hint': ('Read documentation at the following link for more'
' information about how to retrieve the valid file:'
' https://access.redhat.com/articles/3664871')})
rpmname = 'leapp-upgrade-el{}toel{}'.format(get_source_major_version(), get_target_major_version())
hint = (
'All official data files are nowadays part of the installed rpms.'
' This issue is usually encountered when the data files are incorrectly customized, replaced, or removed'
' (e.g. by custom scripts).'
' In case you want to recover the original file, remove it (if still exists)'
' and reinstall the {} rpm.'
.format(rpmname)
)
raise StopActorExecutionError(msg, details={'hint': hint})


def _read_repofile(repofile):
Expand All @@ -145,9 +150,8 @@ def _read_repofile(repofile):
repofile_data = load_data_asset(api.current_actor(),
repofile,
asset_fulltext_name='Repositories mapping',
docs_url='https://access.redhat.com/articles/3664871',
docs_title=('Leapp utility metadata in-place upgrades of RHEL '
'for disconnected upgrades (including Satellite)'))
docs_url='',
docs_title='')
return repofile_data # If the file does not contain a valid json then load_asset will do a stop actor execution


Expand Down
31 changes: 23 additions & 8 deletions repos/system_upgrade/common/libraries/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from leapp import models
from leapp.exceptions import StopActorExecutionError
from leapp.libraries.common.config import get_consumed_data_stream_id, get_env
from leapp.libraries.common.config.version import get_source_major_version, get_target_major_version
from leapp.libraries.stdlib import api

SERVICE_HOST_DEFAULT = "https://cert.cloud.redhat.com"
Expand All @@ -15,15 +16,25 @@
ASSET_PROVIDED_DATA_STREAMS_FIELD = 'provided_data_streams'


def _get_hint():
rpmname = 'leapp-upgrade-el{}toel{}'.format(get_source_major_version(), get_target_major_version())
hint = (
'All official data files are nowadays part of the installed rpms.'
' This issue is usually encountered when the data files are incorrectly customized, replaced, or removed'
' (e.g. by custom scripts).'
' In case you want to recover the original file, remove it (if still exists)'
' and reinstall the {} rpm.'
.format(rpmname)
)
return hint


def _raise_error(local_path, details):
"""
If the file acquisition fails in any way, throw an informative error to stop the actor.
"""
summary = "Data file {lp} is invalid or could not be retrieved.".format(lp=local_path)
hint = ("Read documentation at: https://access.redhat.com/articles/3664871"
" for more information about how to retrieve the file.")

raise StopActorExecutionError(summary, details={'details': details, 'hint': hint})
summary = 'Data file {lp} is missing or invalid.'.format(lp=local_path)
raise StopActorExecutionError(summary, details={'details': details, 'hint': _get_hint()})


def _request_data(service_path, cert, proxies, timeout=REQUEST_TIMEOUT):
Expand Down Expand Up @@ -57,7 +68,8 @@ def read_or_fetch(filename,
service=None,
allow_empty=False,
encoding='utf-8',
data_stream=None):
data_stream=None,
allow_download=True):
"""
Return the contents of a text file or fetch them from an online service if the file does not exist.
Expand All @@ -67,6 +79,7 @@ def read_or_fetch(filename,
:param Optional[str] with_leapp_version: Inject the given leapp version when fetching from a service.
:param bool allow_empty: Raise an error if the resulting data are empty.
:param str encoding: Encoding to use when decoding the raw binary data.
:param bool allow_download: Allow the fallback to download the data file if not present.
:returns: Text contents of the file. Text is decoded using the provided encoding.
:rtype: str
"""
Expand All @@ -75,7 +88,9 @@ def read_or_fetch(filename,

# try to get the data locally
if not os.path.exists(local_path):
logger.warning("File {lp} does not exist, falling back to online service".format(lp=local_path))
if not allow_download:
_raise_error(local_path, "File {lp} does not exist.".format(lp=local_path))
logger.warning("File {lp} does not exist, falling back to online service)".format(lp=local_path))
else:
try:
with io.open(local_path, encoding=encoding) as f:
Expand Down Expand Up @@ -149,7 +164,7 @@ def load_data_asset(actor_requesting_asset,
error_hint = {'hint': ('Read documentation at the following link for more information about how to retrieve '
'the valid file: {0}'.format(docs_url))}
else:
error_hint = {}
error_hint = {'hint': _get_hint()}

data_stream_id = get_consumed_data_stream_id()
data_stream_major = data_stream_id.split('.', 1)[0]
Expand Down

0 comments on commit af6d7ef

Please sign in to comment.