Update ELevate patch

This commit is contained in:
Andrew Lukoshko 2023-06-16 16:52:20 +02:00
parent afc8883046
commit 23a29aa1c9
1 changed files with 17 additions and 139 deletions

View File

@ -791,69 +791,10 @@ index da62c50..f062f78 100644
def get_upgrade_paths_config():
diff --git a/commands/preupgrade/__init__.py b/commands/preupgrade/__init__.py
index 92038bb..8dd8966 100644
--- a/commands/preupgrade/__init__.py
+++ b/commands/preupgrade/__init__.py
@@ -48,6 +48,16 @@ def preupgrade(args, breadcrumbs):
logger = configure_logger('leapp-preupgrade.log')
os.environ['LEAPP_EXECUTION_ID'] = context
+ sentry_client = None
+ sentry_dsn = cfg.get('sentry', 'dsn')
+ if sentry_dsn:
+ try:
+ from raven import Client
+ from raven.transport.http import HTTPTransport
+ sentry_client = Client(sentry_dsn, transport=HTTPTransport)
+ except ImportError:
+ logger.warn("Cannot import the Raven library - remote error logging not functional")
+
try:
repositories = util.load_repositories()
except LeappError as exc:
@@ -56,7 +66,8 @@ def preupgrade(args, breadcrumbs):
workflow = repositories.lookup_workflow('IPUWorkflow')()
util.warn_if_unsupported(configuration)
util.process_whitelist_experimental(repositories, workflow, configuration, logger)
- with beautify_actor_exception():
+
+ with util.format_actor_exceptions(logger, sentry_client):
workflow.load_answers(answerfile_path, userchoices_path)
until_phase = 'ReportsPhase'
logger.info('Executing workflow until phase: %s', until_phase)
@@ -68,12 +79,17 @@ def preupgrade(args, breadcrumbs):
logger.info("Answerfile will be created at %s", answerfile_path)
workflow.save_answers(answerfile_path, userchoices_path)
- util.generate_report_files(context, report_schema)
+
+ util.log_errors(workflow.errors, logger)
+ util.log_inhibitors(context, logger, sentry_client)
report_errors(workflow.errors)
report_inhibitors(context)
+
+ util.generate_report_files(context, report_schema)
report_files = util.get_cfg_files('report', cfg)
log_files = util.get_cfg_files('logs', cfg)
report_info(report_files, log_files, answerfile_path, fail=workflow.failure)
+
if workflow.failure:
sys.exit(1)
diff --git a/commands/upgrade/__init__.py b/commands/upgrade/__init__.py
index c9c2741..f773a5f 100644
index c9c2741..911d11d 100644
--- a/commands/upgrade/__init__.py
+++ b/commands/upgrade/__init__.py
@@ -9,7 +9,7 @@ from leapp.exceptions import CommandError, LeappError
from leapp.logger import configure_logger
from leapp.utils.audit import Execution
from leapp.utils.clicmd import command, command_opt
-from leapp.utils.output import beautify_actor_exception, report_errors, report_info, report_inhibitors
+from leapp.utils.output import report_errors, report_info, report_inhibitors
# NOTE:
# If you are adding new parameters please ensure that they are set in the upgrade function invocation in `rerun`
@@ -18,6 +18,7 @@ from leapp.utils.output import beautify_actor_exception, report_errors, report_i
@command('upgrade', help='Upgrade the current system to the next available major version.')
@ -862,24 +803,7 @@ index c9c2741..f773a5f 100644
@command_opt('reboot', is_flag=True, help='Automatically performs reboot when requested.')
@command_opt('whitelist-experimental', action='append', metavar='ActorName', help='Enable experimental actors')
@command_opt('debug', is_flag=True, help='Enable debug mode', inherit=False)
@@ -77,6 +78,16 @@ def upgrade(args, breadcrumbs):
logger = configure_logger('leapp-upgrade.log')
os.environ['LEAPP_EXECUTION_ID'] = context
+ sentry_client = None
+ sentry_dsn = cfg.get('sentry', 'dsn')
+ if sentry_dsn:
+ try:
+ from raven import Client
+ from raven.transport.http import HTTPTransport
+ sentry_client = Client(sentry_dsn, transport=HTTPTransport)
+ except ImportError:
+ logger.warn("Cannot import the Raven library - remote error logging not functional")
+
if args.resume:
logger.info("Resuming execution after phase: %s", skip_phases_until)
try:
@@ -86,7 +97,13 @@ def upgrade(args, breadcrumbs):
@@ -86,7 +87,13 @@ def upgrade(args, breadcrumbs):
workflow = repositories.lookup_workflow('IPUWorkflow')(auto_reboot=args.reboot)
util.process_whitelist_experimental(repositories, workflow, configuration, logger)
util.warn_if_unsupported(configuration)
@ -890,23 +814,20 @@ index c9c2741..f773a5f 100644
+ logger.info("Upgrade cancelled by user")
+ sys.exit(1)
+
+ with util.format_actor_exceptions(logger, sentry_client):
+ with util.format_actor_exceptions(logger):
logger.info("Using answerfile at %s", answerfile_path)
workflow.load_answers(answerfile_path, userchoices_path)
@@ -98,14 +115,19 @@ def upgrade(args, breadcrumbs):
@@ -98,6 +105,8 @@ def upgrade(args, breadcrumbs):
logger.info("Answerfile will be created at %s", answerfile_path)
workflow.save_answers(answerfile_path, userchoices_path)
+
+ util.log_errors(workflow.errors, logger)
+ util.log_inhibitors(context, logger, sentry_client)
+ util.log_inhibitors(context, logger)
report_errors(workflow.errors)
report_inhibitors(context)
+
util.generate_report_files(context, report_schema)
report_files = util.get_cfg_files('report', cfg)
log_files = util.get_cfg_files('logs', cfg)
@@ -106,6 +115,7 @@ def upgrade(args, breadcrumbs):
report_info(report_files, log_files, answerfile_path, fail=workflow.failure)
if workflow.failure:
@ -915,10 +836,10 @@ index c9c2741..f773a5f 100644
diff --git a/commands/upgrade/util.py b/commands/upgrade/util.py
index 75ffa6a..9022b29 100644
index 75ffa6a..35154be 100644
--- a/commands/upgrade/util.py
+++ b/commands/upgrade/util.py
@@ -2,18 +2,23 @@ import functools
@@ -2,18 +2,25 @@ import functools
import itertools
import json
import os
@ -941,10 +862,12 @@ index 75ffa6a..9022b29 100644
+from leapp.utils.output import report_unsupported, pretty_block_text, pretty_block, Color
from leapp.utils.report import fetch_upgrade_report_messages, generate_report_file
+from leapp.models import ErrorModel
+
+
def disable_database_sync():
@@ -167,6 +172,44 @@ def warn_if_unsupported(configuration):
@@ -167,6 +174,44 @@ def warn_if_unsupported(configuration):
report_unsupported(devel_vars, configuration["whitelist_experimental"])
@ -989,7 +912,7 @@ index 75ffa6a..9022b29 100644
def handle_output_level(args):
"""
Set environment variables following command line arguments.
@@ -236,3 +279,76 @@ def process_report_schema(args, configuration):
@@ -236,3 +281,60 @@ def process_report_schema(args, configuration):
raise CommandError('--report-schema version can not be greater that the '
'actual {} one.'.format(default_report_schema))
return args.report_schema or default_report_schema
@ -1005,7 +928,7 @@ index 75ffa6a..9022b29 100644
+
+
+@contextmanager
+def format_actor_exceptions(logger, sentry):
+def format_actor_exceptions(logger):
+ try:
+ try:
+ yield
@ -1013,10 +936,7 @@ index 75ffa6a..9022b29 100644
+ msg = "{} - Please check the above details".format(err.message)
+ sys.stderr.write("\n")
+ sys.stderr.write(pretty_block_text(msg, color="", width=len(msg)))
+ logger.error(err.message)
+ if sentry:
+ sent_code = sentry.captureException()
+ logger.info("Error \"{}\" sent to Sentry with code {}".format(err, sent_code))
+ logger.error(e.message)
+ finally:
+ pass
+
@ -1043,7 +963,7 @@ index 75ffa6a..9022b29 100644
+ v=details[detail].rstrip().replace('\n', '\n' + ' ' * (6 + len(detail)))))
+
+
+def log_inhibitors(context_id, logger, sentry):
+def log_inhibitors(context_id, logger):
+ from leapp.reporting import Flags # pylint: disable=import-outside-toplevel
+ reports = fetch_upgrade_report_messages(context_id)
+ inhibitors = [report for report in reports if Flags.INHIBITOR in report.get('flags', [])]
@ -1053,19 +973,6 @@ index 75ffa6a..9022b29 100644
+ for position, report in enumerate(inhibitors, start=1):
+ logger.error('{idx:5}. Inhibitor: {title}'.format(idx=position, title=report['title']))
+ logger.info('Consult the pre-upgrade report for details and possible remediation.')
+
+ if sentry:
+ for inhibitor in inhibitors:
+ sentry.captureMessage(
+ "Inhibitor: {}\n"
+ "Severity: {}\n"
+ "{}".format(
+ inhibitor['title'],
+ inhibitor['severity'],
+ inhibitor['summary']
+ )
+ )
+ logger.info("Inhibitor \"{}\" sent to Sentry".format(inhibitor['title']))
diff --git a/etc/leapp/transaction/to_reinstall b/etc/leapp/transaction/to_reinstall
new file mode 100644
index 0000000..c6694a8
@ -1076,28 +983,10 @@ index 0000000..c6694a8
+### Useful for packages that have identical version strings but contain binary changes between major OS versions
+### Packages that aren't installed will be skipped
diff --git a/packaging/leapp-repository.spec b/packaging/leapp-repository.spec
index af4b31d..b9e88a9 100644
index af4b31d..0d8f6c8 100644
--- a/packaging/leapp-repository.spec
+++ b/packaging/leapp-repository.spec
@@ -137,6 +137,8 @@ Requires: pciutils
# Required to gather system facts about SELinux
Requires: libselinux-python
Requires: python-pyudev
+# Required to gather data about actor exceptions or inhibitors
+Requires: python-raven
# required by SELinux actors
Requires: policycoreutils-python
# Required to fetch leapp data
@@ -147,6 +149,8 @@ Requires: python-requests
# systemd-nspawn utility
Requires: systemd-container
Requires: python3-pyudev
+# Required to gather data about actor exceptions or inhibitors
+Requires: python3-raven
# Required to fetch leapp data
Requires: python3-requests
# Required because the code is kept Py2 & Py3 compatible
@@ -196,6 +200,8 @@ rm -rf %{buildroot}%{leapp_python_sitelib}/leapp/cli/commands/tests
@@ -196,6 +196,8 @@ rm -rf %{buildroot}%{leapp_python_sitelib}/leapp/cli/commands/tests
rm -rf %{buildroot}%{repositorydir}/system_upgrade/el8toel9
%else
rm -rf %{buildroot}%{repositorydir}/system_upgrade/el7toel8
@ -6257,14 +6146,3 @@ index 0000000..9df3c0d
+ If no package is installed, this will be `None`.
+ """
+ version = fields.Nullable(fields.String())
diff --git a/requirements.txt b/requirements.txt
index ac6bf9b..f69f981 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -11,5 +11,6 @@ distro==1.5.0
ipaddress==1.0.23
git+https://github.com/oamg/leapp
requests
+raven
# pinning a py27 troublemaking transitive dependency
lazy-object-proxy==1.5.2; python_version < '3'