Skip to content

Commit

Permalink
Return error and inhibitor severity to distinguish it in UI
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Waltlova <[email protected]>
  • Loading branch information
andywaltlova committed Feb 2, 2024
1 parent 3f12656 commit 179d6bf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
8 changes: 8 additions & 0 deletions playbooks/leapp_preupgrade_script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@
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"] = "error"
elif "inhibitor" in groups:
entry["severity"] = "inhibitor"
error_count = len(
[entry for entry in report_entries if "error" in entry.get("groups")]
Expand Down
8 changes: 8 additions & 0 deletions playbooks/leapp_upgrade_script.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,14 @@
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"] = "error"
elif "inhibitor" in groups:
entry["severity"] = "inhibitor"
error_count = len(
[entry for entry in report_entries if "error" in entry.get("groups")]
Expand Down
8 changes: 8 additions & 0 deletions scripts/leapp_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ def parse_results(output, reboot_required=False):
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"] = "error"
elif "inhibitor" in groups:
entry["severity"] = "inhibitor"

error_count = len(
[entry for entry in report_entries if "error" in entry.get("groups")]
Expand Down
31 changes: 25 additions & 6 deletions tests/test_parse_results.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json
import pytest
from mock import mock_open, patch

from scripts.leapp_script import (
Expand All @@ -6,11 +8,18 @@
)


@pytest.mark.parametrize(
("groups_value"),
(
("error"),
("inhibitor"),
),
)
@patch("os.path.exists", return_value=True)
@patch("scripts.leapp_script._find_highest_report_level", return_value="ERROR")
def test_gather_report_files_exist(mock_find_level, mock_exists):
def test_gather_report_files_exist(mock_find_level, mock_exists, groups_value):
test_txt_content = "Test data"
test_json_content = '{"entries": [{"groups": ["error"]}]}'
test_json_content = json.dumps({"entries": [{"groups": [groups_value]}]})
output = OutputCollector()
with patch("__builtin__.open") as mock_open_reports:
return_values = [test_json_content, test_txt_content]
Expand All @@ -19,14 +28,24 @@ def test_gather_report_files_exist(mock_find_level, mock_exists):
)(file, mode)
parse_results(output)

assert mock_find_level.call_count == 1 # entries do not exists -> []
assert mock_find_level.call_count == 1
assert output.status == "ERROR"
assert mock_exists.call_count == 2
assert output.report == test_txt_content
assert output.report_json.get("entries") is not None
assert (
output.message
== "Your system has 1 error and 0 inhibitors out of 1 potential problem."
assert output.report_json.get("entries")[0]["severity"] == groups_value

num_errors = test_json_content.count("error")
errors_str = "%s error%s" % (num_errors, "" if num_errors == 1 else "s")
num_inhibitor = test_json_content.count("inhibitor")
inhibitor_str = "%s inhibitor%s" % (
num_inhibitor,
"" if num_inhibitor == 1 else "s",
)

assert output.message == "Your system has %s and %s out of 1 potential problem." % (
errors_str,
inhibitor_str,
)


Expand Down

0 comments on commit 179d6bf

Please sign in to comment.