Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load data files: update hints in error messages and prepare for the download drop #1121

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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