diff --git a/playbooks/leapp_preupgrade_script.yaml b/playbooks/leapp_preupgrade_script.yaml index 53c7641..b3a27a9 100644 --- a/playbooks/leapp_preupgrade_script.yaml +++ b/playbooks/leapp_preupgrade_script.yaml @@ -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")] diff --git a/playbooks/leapp_upgrade_script.yaml b/playbooks/leapp_upgrade_script.yaml index 9a36f8e..33b7b02 100644 --- a/playbooks/leapp_upgrade_script.yaml +++ b/playbooks/leapp_upgrade_script.yaml @@ -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")] diff --git a/scripts/leapp_script.py b/scripts/leapp_script.py index b253580..06cd40f 100644 --- a/scripts/leapp_script.py +++ b/scripts/leapp_script.py @@ -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")] diff --git a/tests/test_parse_results.py b/tests/test_parse_results.py index a5fee98..59526d8 100644 --- a/tests/test_parse_results.py +++ b/tests/test_parse_results.py @@ -1,3 +1,5 @@ +import json +import pytest from mock import mock_open, patch from scripts.leapp_script import ( @@ -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] @@ -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, )