def test_convert_from_error_to_report(): error_dict_no_details = { 'message': 'The system is not registered or subscribed.', 'time': '2019-11-19T05:13:04.447562Z', 'details': None, 'actor': 'verify_check_results', 'severity': 'error' } report = create_report_from_error(error_dict_no_details) assert report['severity'] == 'high' assert report['title'] == 'The system is not registered or subscribed.' assert report['audience'] == 'sysadmin' assert report['summary'] == '' error_dict_with_details = { 'message': 'The system is not registered or subscribed.', 'time': '2019-11-19T05:13:04.447562Z', 'details': 'Some other info that should go to report summary', 'actor': 'verify_check_results', 'severity': 'error' } report = create_report_from_error(error_dict_with_details) assert report['severity'] == 'high' assert report['title'] == 'The system is not registered or subscribed.' assert report['audience'] == 'sysadmin' assert report[ 'summary'] == 'Some other info that should go to report summary'
def fetch_upgrade_report_messages(context_id): """ :param context_id: ID to identify the needed messages :type context_id: str :return: All upgrade messages of type "Report" withing the given context """ report_msgs = get_messages(names=['Report', 'ErrorModel'], context=context_id) or [] messages = [] for message in report_msgs: data = message['message']['data'] # We need to be able to uniquely identify each message so we compute # a hash of: context UUID, message ID in the database and hash of the # data section of the message itself sha256 = hashlib.sha256() sha256.update(message['message']['hash'].encode('utf-8')) sha256.update(message['context'].encode('utf-8')) sha256.update(str(message['id']).encode('utf-8')) envelope = { 'timeStamp': message['stamp'], 'hostname': message['hostname'], 'actor': message['actor'], 'id': sha256.hexdigest() } data_json = json.loads(data) report = json.loads(data_json.get('report', "{}")) if not report: # transform Error message to Report message report = create_report_from_error(data_json) report.update(envelope) messages.append(report) messages.extend(_create_reports_from_deprecations(context_id)) return messages