From 54ec7557dba38fcf7427ff53772073c49a200ff6 Mon Sep 17 00:00:00 2001 From: ZhouWeitao Date: Sat, 24 Sep 2022 17:05:47 +0800 Subject: [PATCH] patch: report a default external link Signed-off-by: ZhouWeitao --- ...-0004-report-a-default-external-link.patch | 81 +++++++++++++++++++ leapp.spec | 6 +- 2 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 leapp-0004-report-a-default-external-link.patch diff --git a/leapp-0004-report-a-default-external-link.patch b/leapp-0004-report-a-default-external-link.patch new file mode 100644 index 0000000..5438525 --- /dev/null +++ b/leapp-0004-report-a-default-external-link.patch @@ -0,0 +1,81 @@ +diff -uNrp leapp-0.12.0.orig/leapp/reporting/__init__.py leapp-0.12.0/leapp/reporting/__init__.py +--- leapp-0.12.0.orig/leapp/reporting/__init__.py 2022-09-22 22:57:11.850595108 +0800 ++++ leapp-0.12.0/leapp/reporting/__init__.py 2022-09-23 23:19:22.578609278 +0800 +@@ -198,6 +198,16 @@ class ExternalLink(BaseListPrimitive): + def path(self): + return ('detail', 'external') + ++ def __repr__(self): ++ return "[{}] {}".format(self._value['title'], self._value['url']) ++ ++ @classmethod ++ def from_dict(cls, data): ++ values = [] ++ for value in data.get('external', []): ++ values.append(ExternalLink(value.get('url', ''), value.get('title', ''))) ++ return values ++ + + class RelatedResource(BaseListPrimitive): + """Report detail field for related resources (e.g. affected packages/files)""" +@@ -289,6 +299,7 @@ def _sanitize_entries(entries): + if not any(isinstance(e, Audience) for e in entries): + entries.append(Audience('sysadmin')) + _check_stable_key(entries, raise_if_undefined=os.getenv('LEAPP_DEVEL_FIXED_REPORT_KEY', '0') != '0') ++ _check_external_link(entries) + + + def _check_stable_key(entries, raise_if_undefined=False): +@@ -325,6 +336,31 @@ def _check_stable_key(entries, raise_if_ + logger.warning('Stable Key report entry not provided, dynamically generating one - {}'.format(key_value)) + + ++def _check_external_link(entries): ++ """ ++ Inserts a default ExternalLink into the entries of the report if it doesn't exist. ++ ++ The default one is giving a stable AOMS knowledge base url and users can query the expected ++ content by the entry 'Key' ++ """ ++ def _find_entry(cls): ++ entry = next((e for e in entries if isinstance(e, cls)), None) ++ if entry: ++ return entry._value ++ ++ logger = logging.getLogger('leapp.reporting') ++ external_link = _find_entry(ExternalLink) ++ if external_link: ++ # ExternalLink is already there ++ return ++ ++ # No ExternalLink found - let's use the common one! ++ url = "https://www.yuque.com/anolis-docs/kbase/gk90ag" ++ title = "Anolis OS Migration System(AOMS) Knowledge Base, visit it and query the content by the given Key" ++ entries.append(ExternalLink(url, title)) ++ logger.warning('Special ExternalLink report entry not provided, using the default one - {}'.format(url)) ++ ++ + def _create_report_object(entries): + report = {} + +diff -uNrp leapp-0.12.0.orig/leapp/utils/report.py leapp-0.12.0/leapp/utils/report.py +--- leapp-0.12.0.orig/leapp/utils/report.py 2022-09-22 22:57:11.850595108 +0800 ++++ leapp-0.12.0/leapp/utils/report.py 2022-09-23 23:20:04.895895225 +0800 +@@ -2,7 +2,7 @@ import hashlib + import json + import os + +-from leapp.reporting import Remediation, Severity, create_report_from_error, create_report_from_deprecation ++from leapp.reporting import Remediation, Severity, ExternalLink, create_report_from_error, create_report_from_deprecation + from leapp.utils.audit import get_messages, get_audit_entry + + +@@ -101,6 +101,8 @@ def generate_report_file(messages_to_rep + if remediation: + f.write('Remediation: {}\n'.format(remediation)) + f.write('Key: {}\n'.format(message['key'])) ++ for external_link in ExternalLink.from_dict(message.get('detail', {})): ++ f.write('ExternalLink: {}\n'.format(external_link)) + f.write('-' * 40 + '\n') + elif path.endswith(".json"): + with open(path, 'w') as f: diff --git a/leapp.spec b/leapp.spec index 3659fcb..8925f16 100644 --- a/leapp.spec +++ b/leapp.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.2 +%define anolis_release .0.3 # IMPORTANT: this is for the leapp-framework capability (it's not the real # version of the leapp). The capability reflects changes in api and whatever # functionality important from the point of repository. In case of @@ -39,6 +39,7 @@ BuildArch: noarch Patch0001: leapp-0001-add-remove-actor-parament.patch Patch0002: leapp-0002-add-command-no-rhsm_skip.patch Patch0003: leapp-0003-add-disablerepo-option-to-upgrade-kernel-to-RHCK.patch +Patch0004: leapp-0004-report-a-default-external-link.patch %if !0%{?fedora} %if %{with python3} @@ -280,6 +281,9 @@ rm -f %{buildroot}/%{_bindir}/leapp # no files here %changelog +* Sat Sep 24 2022 Weitao Zhou - 0.12.0-1.0.3 +- patch: report a default external link + * Tue Sep 13 2022 mgb01105731 - 0.12.0-1.0.2 - patch: add disablerepo option to upgrade kernel to RHCK -- Gitee