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

Feat/findings level #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions playbooks/leapp-preupgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
package_facts:
manager: auto

- name: Set initial findings level
set_fact:
findings_level: 1

- name: Set rhui_packages_found to empty list
set_fact:
rhui_packages_found: []
Expand Down Expand Up @@ -203,6 +207,15 @@
out of {{ total_problems_count }} potential problems.
when: inhibitor_count != "0" or error_count != "0"

- name: Set findings level based on inhibitor count
set_fact:
findings_level: 5
when: inhibitor_count != "0"

- name: Set findings level based on error count
set_fact:
findings_level: 7
when: error_count != "0"

- name: Set message if no inhibitors and no errors present
set_fact:
Expand All @@ -218,6 +231,7 @@
report: "{{ report_content_txt_raw.content | b64decode }}"
message: "{{ message }}"
alert: "{{ (inhibitor_count | int > 0) or (error_count | int > 0) }}"
findings_level: "{{ findings_level }}"

- name: Start insights-client for immediate data collection of leapp-report
ansible.builtin.shell: insights-client >/dev/null 2>&1 &
Expand Down
11 changes: 11 additions & 0 deletions playbooks/leapp-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@
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 findings level based on inhibitor count
set_fact:
findings_level: 5
when: inhibitor_count != "0"

- name: Set findings level based on error count
set_fact:
findings_level: 7
when: error_count != "0"

- name: Set message if leapp upgrade succeeded
set_fact:
message: >-
Expand All @@ -226,6 +236,7 @@
report: "{{ report_content_txt_raw.content | b64decode }}"
message: "{{ message }}"
alert: "{{ not is_leapp_upgrade_successful }}"
findings_level: "{{ findings_level }}"

- name: Start insights-client for immediate data collection of leapp-report
ansible.builtin.shell: insights-client >/dev/null 2>&1
Expand Down
75 changes: 75 additions & 0 deletions schemas/leapp_schema_2.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"title": "Leapp pre-upgrade script schema",
"description": "Script is expected to set up Leapp and run pre-upgrade analysis. This schema defines the output format that is expected by Red Hat Insights Task UI.",
"type": "object",
"properties": {
"alert": {
"type": "boolean"
},
"error": {
"type": "boolean"
},
"status": {
"$ref": "#/$defs/status_codes"
},
"report": {
"type": "string"
},
"message": {
"type": "string"
},
"report_json": {
"oneOf": [
{
"type": "null"
},
{
"type": "object",
"properties": {
"entries": {
"type": "object"
},
"tasks_format_version": {
"type": "string"
},
"tasks_format_id": {
"type": "string"
}
},
"required": [
"entries",
"tasks_format_version",
"tasks_format_id"
]
}
]
},
"findings_level": {
"type": "integer",
"minimum": 0,
"maximum": 10
}
},
"required": [
"alert",
"error",
"status",
"message",
"report",
"report_json",
"findings_level"
],
"additionalProperties": false,
"$defs": {
"status_codes": {
"description": "The severity of the results and messages",
"type": "string",
"enum": [
"SUCCESS",
"INFO",
"WARNING",
"ERROR"
]
}
}
}
25 changes: 15 additions & 10 deletions scripts/leapp_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ class OutputCollector(object):
# Nine and six is reasonable in this case.

def __init__(
self, status="", message="", report="", entries=None, alert=False, error=False
self, status="", message="", report="", entries=None, alert=False, error=False, findings_level=1,
):
self.status = status
self.status = status # empty default, to be set based on script results
self.alert = alert # true if error true or if pre-upgrade inhibited
self.findings_level = findings_level # value between 1-10

# NOTE: currently false everywhere
# here for consistency with conversions scripts
Expand Down Expand Up @@ -81,6 +82,7 @@ def to_dict(self):
"status": self.status,
"alert": self.alert,
"error": self.error,
"findings_level": self.findings_level,
"message": self.message,
"report": self.report,
"report_json": self.report_json,
Expand Down Expand Up @@ -305,14 +307,9 @@ def _find_highest_report_level(entries):
Gather status codes from entries.
"""
print("Collecting and combining report status.")
action_level_combined = [value["severity"] for value in entries]

valid_action_levels = [
level for level in action_level_combined if level in STATUS_CODE
]
valid_action_levels.sort(key=lambda status: STATUS_CODE[status], reverse=True)
return STATUS_CODE_NAME_MAP[valid_action_levels[0]]

valid_entries_levels = [value["severity"] for value in entries if value["severity"] in STATUS_CODE]
valid_entries_levels.sort(key=lambda status: STATUS_CODE[status], reverse=True)
return STATUS_CODE_NAME_MAP[valid_entries_levels[0]]

def parse_results(output, reboot_required=False):
print("Processing {} results ...".format(SCRIPT_TYPE.title()))
Expand All @@ -321,6 +318,7 @@ def parse_results(output, reboot_required=False):
message = "Can't open json report at " + JSON_REPORT_PATH
alert = True
status = "ERROR"
findings_level = 1

print("Reading JSON report")
if os.path.exists(JSON_REPORT_PATH):
Expand Down Expand Up @@ -361,6 +359,10 @@ def parse_results(output, reboot_required=False):
"" if len(report_entries) == 1 else "s",
)
)
if error_count > 0:
findings_level = 7
if inhibitor_count > 0:
findings_level = 5

if reboot_required:
message = (
Expand All @@ -378,6 +380,7 @@ def parse_results(output, reboot_required=False):
output.report_json = report_json
output.alert = alert
output.message = message
output.findings_level = findings_level

print("Reading TXT report")
report_txt = "Not found"
Expand Down Expand Up @@ -456,6 +459,7 @@ def main():
error=False,
message=exception.message,
report=exception.report,
findings_level=7,
)
except Exception as exception:
print(str(exception))
Expand All @@ -465,6 +469,7 @@ def main():
error=False,
message="An unexpected error occurred. Expand the row for more details.",
report=str(exception),
findings_level=10,
)
finally:
print("### JSON START ###")
Expand Down
Loading
Loading