diff --git a/schemas/conversion_schema_1.0.json b/schemas/conversion_schema_1.0.json index 4a0e6e5..b7faa5f 100644 --- a/schemas/conversion_schema_1.0.json +++ b/schemas/conversion_schema_1.0.json @@ -6,6 +6,12 @@ "status": { "$ref": "#/$defs/status_codes" }, + "alert": { + "type": "boolean" + }, + "error": { + "type": "boolean" + }, "report": { "type": "string" }, @@ -41,6 +47,7 @@ }, "required": [ "status", + "alert", "message", "report", "report_json" diff --git a/scripts/conversion_script.py b/scripts/conversion_script.py index 143e3e6..946d2d9 100644 --- a/scripts/conversion_script.py +++ b/scripts/conversion_script.py @@ -45,8 +45,16 @@ def __init__(self, message, report): class OutputCollector(object): """Wrapper class for script expected stdout""" - def __init__(self, status="", message="", report="", entries=None): + # pylint: disable=too-many-instance-attributes + # pylint: disable=too-many-arguments + # Eight and five is reasonable in this case. + + def __init__( + self, status="", message="", report="", entries=None, alert=False, error=False + ): self.status = status + self.alert = alert # true if error true or if conversion inhibited + self.error = error # true if the script wasn't able to finish, otherwise false self.message = message self.report = report self.tasks_format_version = "1.0" @@ -67,6 +75,8 @@ def to_dict(self): return { "status": self.status, + "alert": self.alert, + "error": self.error, "message": self.message, "report": self.report, "report_json": self.report_json, @@ -143,14 +153,16 @@ def gather_textual_report(): def generate_report_message(highest_status): """Generate a report message based on the status severity.""" message = "" + alert = False if STATUS_CODE[highest_status] <= STATUS_CODE["WARNING"]: message = "No problems found. The system was converted successfully." if STATUS_CODE[highest_status] > STATUS_CODE["WARNING"]: message = "The conversion cannot proceed. You must resolve existing issues to perform the conversion." + alert = True - return message + return message, alert def setup_convert2rhel(required_files): @@ -445,7 +457,7 @@ def main(): # Generate report message and transform the raw data into entries for # Insights. - output.message = generate_report_message(highest_level) + output.message, output.alert = generate_report_message(highest_level) output.entries = transform_raw_data(data) update_insights_inventory() print("Conversion script finish successfully!") @@ -453,6 +465,8 @@ def main(): print(exception.report) output = OutputCollector( status="ERROR", + alert=True, + error=True, message=exception.message, report=exception.report, ) @@ -460,6 +474,8 @@ def main(): print(str(exception)) output = OutputCollector( status="ERROR", + alert=True, + error=True, message="An unexpected error occurred. Expand the row for more details.", report=str(exception), ) diff --git a/tests/conversion_script/test_generate_report_message.py b/tests/conversion_script/test_generate_report_message.py index 31ae41d..a53127b 100644 --- a/tests/conversion_script/test_generate_report_message.py +++ b/tests/conversion_script/test_generate_report_message.py @@ -3,16 +3,17 @@ @pytest.mark.parametrize( - ("highest_status", "expected_message"), + ("highest_status", "expected_message", "has_alert"), [ - ("SUCCESS", "No problems found. The system was converted successfully."), - ("INFO", "No problems found. The system was converted successfully."), - ("WARNING", "No problems found. The system was converted successfully."), + ("SUCCESS", "No problems found. The system was converted successfully.", False), + ("INFO", "No problems found. The system was converted successfully.", False), + ("WARNING", "No problems found. The system was converted successfully.", False), ( "ERROR", "The conversion cannot proceed. You must resolve existing issues to perform the conversion.", + True, ), ], ) -def test_generate_report_message(highest_status, expected_message): - assert generate_report_message(highest_status) == expected_message +def test_generate_report_message(highest_status, expected_message, has_alert): + assert generate_report_message(highest_status) == (expected_message, has_alert) diff --git a/tests/conversion_script/test_main.py b/tests/conversion_script/test_main.py index 2817d1f..d9a010b 100644 --- a/tests/conversion_script/test_main.py +++ b/tests/conversion_script/test_main.py @@ -14,7 +14,7 @@ @patch("scripts.conversion_script.run_convert2rhel", side_effect=Mock()) @patch("scripts.conversion_script.find_highest_report_level", side_effect=Mock(return_value=["SUCCESS"])) @patch("scripts.conversion_script.gather_textual_report", side_effect=Mock(return_value="")) -@patch("scripts.conversion_script.generate_report_message", side_effect=Mock(return_value="")) +@patch("scripts.conversion_script.generate_report_message", side_effect=Mock(return_value=("", False))) @patch("scripts.conversion_script.transform_raw_data", side_effect=Mock(return_value="")) @patch("scripts.conversion_script.cleanup", side_effect=Mock()) # fmt: on @@ -55,7 +55,7 @@ def test_main_success( @patch("scripts.conversion_script.run_convert2rhel", side_effect=ProcessError("test", "Process error")) @patch("scripts.conversion_script.find_highest_report_level", side_effect=Mock(return_value=["SUCCESS"])) @patch("scripts.conversion_script.gather_textual_report", side_effect=Mock(return_value="")) -@patch("scripts.conversion_script.generate_report_message", side_effect=Mock(return_value="")) +@patch("scripts.conversion_script.generate_report_message", side_effect=Mock(return_value=("", False))) @patch("scripts.conversion_script.cleanup", side_effect=Mock()) # fmt: on def test_main_process_error( @@ -92,7 +92,7 @@ def test_main_process_error( @patch("scripts.conversion_script.run_convert2rhel", side_effect=Mock()) @patch("scripts.conversion_script.find_highest_report_level", side_effect=Mock(return_value=["SUCCESS"])) @patch("scripts.conversion_script.gather_textual_report", side_effect=Mock(return_value="")) -@patch("scripts.conversion_script.generate_report_message", side_effect=Mock(return_value="")) +@patch("scripts.conversion_script.generate_report_message", side_effect=Mock(return_value=("", False))) @patch("scripts.conversion_script.cleanup", side_effect=Mock()) # fmt: on def test_main_general_exception( diff --git a/tests/conversion_script/test_output_schema.py b/tests/conversion_script/test_output_schema.py index aaff11f..5e58784 100644 --- a/tests/conversion_script/test_output_schema.py +++ b/tests/conversion_script/test_output_schema.py @@ -9,7 +9,7 @@ def test_output_schema(): output_collector = OutputCollector(status=status) empty_output = output_collector.to_dict() - with open("schemas/preconversion_assessment_schema_1.0.json", "r") as schema: + with open("schemas/conversion_schema_1.0.json", "r") as schema: schema_json = json.load(schema) # If some difference between generated json and its schema invoke exception jsonschema.validate(instance=empty_output, schema=schema_json) @@ -26,7 +26,7 @@ def test_output_schema_entries_report(): output_collector.entries = {"hi": "world"} full_output = output_collector.to_dict() - with open("schemas/preconversion_assessment_schema_1.0.json", "r") as schema: + with open("schemas/conversion_schema_1.0.json", "r") as schema: schema_json = json.load(schema) # If some difference between generated json and its schema invoke exception jsonschema.validate(instance=full_output, schema=schema_json)