Skip to content

Commit

Permalink
Merge pull request #12 from oamg/feat/distinguish-errors-inhibitors-s…
Browse files Browse the repository at this point in the history
…everity

Return error and inhibitor severity to distinguish it in UI
  • Loading branch information
andywaltlova authored Feb 9, 2024
2 parents 4611548 + 92ed176 commit 04ec8ce
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 118 deletions.
73 changes: 51 additions & 22 deletions playbooks/leapp_preupgrade_ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,7 @@
no_rhsm: false
insights_signature_exclude: /hosts,/vars/insights_signature
insights_signature: !!binary |
TFMwdExTMUNSVWRKVGlCUVIxQWdVMGxIVGtGVVZWSkZMUzB0TFMwS1ZtVnljMmx2YmpvZ1IyNTFV
RWNnZGpFS0NtbFJTV05DUVVGQ1EwRkJSMEpSU214SWRHVXdRVUZ2U2tWTmRuYzFPRVFyYWpWd1Rs
QnFWVkF2TVZjek5EWlpTME5yTkdKTE4ydDNiSHBQU3pGMVVqZ0tNRzU1U2xoQ2MxZDViRFJYVEdk
MU1ua3hWR1p1VW5wRmVEWmpSVWxXVEU1TmVFbEJjVFJzYkVaTGRVSXpSalpLUlRKTE56WlhSR3hH
YkRVMFJIVlNUZ3AxVml0MGFYcFZTWE50TDJaSVUyUXZTM013TWtKeWJscG1VbVZpU25kbFRXOTZO
Mjl2VGxabGJFNXZOV1pXTlhsb2R6SkljVVJQZUZReWVGSk9OSE0wQ25wRU9XNU9lblpPV2xBMUsx
bFFURW8zWlV0VWFETTFMMVJtVGxwWVRsZEJXVE52U3pCVVpDOVNRM05TZWtwcWNUWkdkVlZuYVRC
RWJHUjZTMWMyYmxrS1F6ZFdMMHh5YlhsMFV6RjJaQ3RsY0ZKbGRHNTBVME5oYURGNEsyaFNWWEJ1
TjFJMmFWbG9TVlEzYldGeVduVmpVWEpVV1RWM2FYZE9aM0ZXZDNKbVp3bzFNMDlLT1dRNU9GRm9X
a1pMUzB4TWNFcHpZa0l5UjA5QldtNTJkbUo2UVRjeWN5dElXVXhPVkhCTVNFRlVSSGhRTmpFdmNr
NUpaemxIWlhWM1oydFZDa1YzTHpkRldsTXpOSFpUYVdSYVZVMVBXV1o2VTBJeldqUllXbk5sVEhO
NFFVc3pOMng2Y1U4elpFTjVWbk5wWVdOMVVWVklaV3hRTUZaNlNURk9la2tLVGxoVFprWjFaM3Ax
WTJKSmNFbDJNek5UWm5SdGFVRkJUVTFtYkVwWmVsVjJMemhwWmpWUldVdGxTbHBYVjBGRFVIVm5k
MXBGWlRSQlZEVXpOekZuYkFwRE5FbDZNalowYm5aTlRHdGpRa3hEWjIxaFpTOVBUbUkwTUROTWFr
TnNSa1ZJTUV0aVduUnJhV2xxVlc1MGNWbHZURlJhZGtJM09VdHdibFJEZDJWcUNub3ZkRGR3V1V0
aU5sbFhZbEJTZEZOdU9HbERSamM1UmxaRFpURlJMMHhMUmpGVVVVbHlXRVpKTDJ4NFlUaHZNSGRU
TjFsRGJrUXJiRGxDVDJwMVFuY0tibE5NY0ZoeWQwMXdaVWN6YjBKYVQyMWxhV05RTW5WVVpFUlJV
MWxXTkV0TU9WSTRORGwwUkVkaE5YUnJlRk5IVTFsamVXVklVRTlwYW01SlpXeENVd3AwYkZkbmVu
RTRSR2t3UTA5c09GbDRZa2t6VEFvOWMzSXhSd290TFMwdExVVk9SQ0JRUjFBZ1UwbEhUa0ZVVlZK
RkxTMHRMUzBL
ascii_armored gpg signature
tasks:
- name: Exit for non-eligible releases
ansible.builtin.meta: end_host
Expand Down Expand Up @@ -174,6 +155,10 @@
ansible.builtin.set_fact:
report_content: "{{ report_content_raw.content | b64decode }}"

- name: Set total problems count
ansible.builtin.set_fact:
total_problems_count: "{{ report_content.entries | length }}"

- name: Set inhibitor count
ansible.builtin.set_fact:
inhibitor_count: "{{ report_content.entries | selectattr('groups', 'defined') | selectattr('groups', 'contains', 'inhibitor') | list | length }}"
Expand All @@ -182,12 +167,56 @@
ansible.builtin.set_fact:
error_count: "{{ report_content.entries | selectattr('groups', 'defined') | selectattr('groups', 'contains', 'error') | list | length }}"

- name: Init new empty entries for edited severity
ansible.builtin.set_fact:
report_content_edited: >-
{{
{
"entries": []
}
}}
- name: Transform severities in leapp report to distinguish errors and inhibitors from other high risks entries
set_fact:
report_content_edited: >-
{{
report_content_edited | combine(
{
"entries": report_content_edited.entries | default([]) +
[
entry | combine(
{"severity": "inhibitor"} if "error" in entry.groups | default([]) else
{"severity": "inhibitor"} if "inhibitor" in entry.groups | default([]) else {}
)
]
}
)
}}
loop: "{{ report_content.entries | default([]) }}"
loop_control:
loop_var: entry

- name: Set message if inhibitors or errors present
set_fact:
message: >-
"The upgrade cannot proceed. Your system has {{ error_count | int + inhibitor_count | int }} inhibitor{{ 's' if inhibitor_count | int + error_count | int != 1 else '' }}
out of {{ total_problems_count }} potential problems."
when: inhibitor_count != "0" or error_count != "0"


- name: Set message if no inhibitors and no errors present
set_fact:
message: >-
{{ 'No problems found. The system is ready for upgrade.' if total_problems_count == 0
else 'The upgrade can proceed. However, there is one or more warnings about issues that might occur after the upgrade.'}}
when: inhibitor_count == "0" and error_count == "0"

- name: Set result
ansible.builtin.set_fact:
task_results:
report_json: "{{ report_content }}"
report_json: "{{ report_content_edited }}"
report: "{{ report_content_txt_raw.content | b64decode }}"
message: "Your system has {{ error_count }} errors and {{ inhibitor_count }} inhibitors out of {{report_content.entries | length}} potential problems."
message: "{{ message }}"
alert: "{{ (inhibitor_count | int > 0) or (error_count | int > 0) }}"

- name: Start insights-client for immediate data collection of leapp-report
Expand Down
60 changes: 40 additions & 20 deletions playbooks/leapp_preupgrade_script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
TXT_REPORT_PATH = "/var/log/leapp/leapp-report.txt"
REBOOT_GUIDANCE_MESSAGE = "A reboot is required to continue. Please reboot your system."
ALLOWED_RHEL_RELEASES = ["7", "8"]
# Based on https://github.com/oamg/leapp/blob/master/report-schema-v110.json#L211
STATUS_CODE = {
"inhibitor": 4,
"high": 3,
"medium": 2,
"low": 1,
"info": 0,
}
STATUS_CODE_NAME_MAP = {
"inhibitor": "ERROR",
"high": "ERROR",
"medium": "WARNING",
"low": "WARNING",
Expand Down Expand Up @@ -111,7 +115,7 @@
"""Check if the release is eligible for upgrade or preupgrade."""
print("Exit if not RHEL 7 or RHEL 8 ...")
major_version, _ = release.split(".") if release is not None else (None, None)
return release is None or major_version not in ["7", "8"]
return release is None or major_version not in ALLOWED_RHEL_RELEASES
# Code taken from
Expand Down Expand Up @@ -308,9 +312,7 @@
Gather status codes from entries.
"""
print("Collecting and combining report status.")
action_level_combined = []
for value in entries:
action_level_combined.append(value["severity"])
action_level_combined = [value["severity"] for value in entries]
valid_action_levels = [
level for level in action_level_combined if level in STATUS_CODE
Expand All @@ -333,29 +335,44 @@
report_json = json.load(handler)
report_entries = report_json.get("entries", [])
for entry in report_entries:
groups = entry.get("groups", [])
# NOTE: "severity" key in report is connected to tasks-frontend severity maps
# Every change must come with change to severity maps otherwise UI will throw sentry errors
if "error" in groups:
entry["severity"] = "inhibitor"
elif "inhibitor" in groups:
entry["severity"] = "inhibitor"
total_problems_count = len(report_entries)
error_count = len(
[entry for entry in report_entries if "error" in entry.get("groups")]
)
inhibitor_count = len(
[entry for entry in report_entries if "inhibitor" in entry.get("groups")]
)
message = (
"Your system has %s error%s and %s inhibitor%s out of %s potential problem%s."
% (
error_count,
"" if error_count == 1 else "s",
inhibitor_count,
"" if inhibitor_count == 1 else "s",
len(report_entries),
"" if len(report_entries) == 1 else "s",
if inhibitor_count == 0 and error_count == 0:
if total_problems_count == 0:
message = "No problems found. The system is ready for upgrade."
else:
message = "The upgrade can proceed. However, there is one or more warnings about issues that might occur after the upgrade."
else:
message = (
"The upgrade cannot proceed. "
"Your system has %s inhibitor%s out of %s potential problem%s."
% (
inhibitor_count + error_count,
"" if inhibitor_count + error_count == 1 else "s",
len(report_entries),
"" if len(report_entries) == 1 else "s",
)
)
)
if reboot_required:
problem_info = message.lstrip("Your system has ").rstrip(".")
message = (
"System will be upgraded (%s). Rebooting system in 1 minute."
% problem_info
"No problems found. System will be upgraded. Rebooting system in 1 minute. "
"After reboot check inventory to verify the system is registered with new RHEL major version."
)
alert = inhibitor_count > 0 or error_count > 0
status = (
Expand All @@ -372,7 +389,7 @@
print("Reading TXT report")
report_txt = "Not found"
if os.path.exists(TXT_REPORT_PATH):
with open(JSON_REPORT_PATH, mode="r") as handler:
with open(TXT_REPORT_PATH, mode="r") as handler:
report_txt = handler.read()
output.report = report_txt
Expand Down Expand Up @@ -410,8 +427,11 @@
# Exit if not eligible release
dist, version = get_rhel_version()
if dist != "rhel" or is_non_eligible_releases(version):
message = "In-place upgrades are supported only on RHEL %s." % ",".join(
ALLOWED_RHEL_RELEASES
)
raise ProcessError(
message="In-place upgrades are supported only on RHEL distributions.",
message=message,
report='Exiting because distribution="%s" and version="%s"'
% (dist, version),
)
Expand Down
78 changes: 52 additions & 26 deletions playbooks/leapp_upgrade_ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,8 @@
no_rhsm: false
is_leapp_upgrade_successful: false
insights_signature_exclude: /hosts,/vars/insights_signature
insights_signature: !!binary |
TFMwdExTMUNSVWRKVGlCUVIxQWdVMGxIVGtGVVZWSkZMUzB0TFMwS1ZtVnljMmx2YmpvZ1IyNTFV
RWNnZGpFS0NtbFJTV05DUVVGQ1EwRkJSMEpSU214SWRHVm9RVUZ2U2tWTmRuYzFPRVFyYWpWd1Rr
NHhUVkZCU20welYyMTRWRXhxUjJGSFdXMHpaRk5EZFM5MU5EWUtORGRoYUcxSE1TdERlV3hZU21S
U2JuSTFSRE4zWWpJd1JVRkVOVGR3YmtGSkwyNDBaakJLZHpoVGNFeENabUZ3YldOd2RHRlNTMVJ6
UW1WRVNVMHJZUXB6WVRFd09FdzVPQ3RLUVhBNU16RkNjMFl2UlZaSWJtd3dkVmRhTHpaaVJ6UlNO
R0ZxUW5GQldEUXhkamhwWkU1R2VWSjBNSFpSVld0QmNTOVVOV2R5Q25Vd1ZFeEhhMVp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tasks:
- name: Exit for non-eligible releases
ansible.builtin.meta: end_host
Expand Down Expand Up @@ -176,27 +157,72 @@
ansible.builtin.set_fact:
report_content: "{{ report_content_raw.content | b64decode }}"

- name: Set total problems count
ansible.builtin.set_fact:
total_problems_count: "{{ report_content.entries | length }}"

- name: Set inhibitor count
ansible.builtin.set_fact:
inhibitor_count: "{{ report_content.entries | selectattr('groups', 'defined') | selectattr('groups', 'contains', 'inhibitor') | list | length }}"

- name: Set errors count
ansible.builtin.set_fact:
error_count: "{{ report_content.entries | selectattr('groups', 'defined') | selectattr('groups', 'contains', 'error') | list | length }}"

- name: Init new empty entries for report with edited severity
ansible.builtin.set_fact:
report_content_edited: >-
{{
{
"entries": []
}
}}
- name: Transform severities in leapp report to distinguish errors and inhibitors from other high risks entries
set_fact:
report_content_edited: >-
{{
report_content_edited | combine(
{
"entries": report_content_edited.entries | default([]) +
[
entry | combine(
{"severity": "inhibitor"} if "error" in entry.groups | default([]) else
{"severity": "inhibitor"} if "inhibitor" in entry.groups | default([]) else {}
)
]
}
)
}}
loop: "{{ report_content.entries | default([]) }}"
loop_control:
loop_var: entry

- name: Prepare final result
block:
- name: Set default fail message
set_fact:
message: "Upgrade of your system failed. Please check the /var/log/leapp/leapp-report.json and /var/log/rhc-worker-playbook/ansible logs for details."
message: >-
"The upgrade cannot proceed.
Your system has {{ error_count | int + inhibitor_count | int }} inhibitor{{ 's' if inhibitor_count | int + error_count | int != 1 else '' }}
out of {{ total_problems_count }} potential problems."
- name: Set message if leapp upgrade succeeded
set_fact:
message: "Upgrade ran successfully. System has now been rebooted. If everything works fine, the system is running the new RHEL version after reboot. Check inventory to verify the system is\
\ in new major version."
message: >-
"No problems found. The system will be upgraded. Rebooting system in 1 minute.
After reboot check inventory to verify the RHEL system is registered with new major version."
when: is_leapp_upgrade_successful is true

- name: Set report content as empty if upgrade was successful
set_fact:
report_content: ""
report_content_edited: ""
when: is_leapp_upgrade_successful is true

- name: Set result
ansible.builtin.set_fact:
task_results:
report_json: "{{ report_content }}"
report_json: "{{ report_content_edited }}"
report: "{{ report_content_txt_raw.content | b64decode }}"
message: "{{ message }}"
alert: "{{ not is_leapp_upgrade_successful }}"
Expand Down
Loading

0 comments on commit 04ec8ce

Please sign in to comment.