Skip to content

Commit

Permalink
remove the truncation error object
Browse files Browse the repository at this point in the history
  • Loading branch information
feng-j678 committed Oct 23, 2023
1 parent baa2968 commit 061c365
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 93 deletions.
31 changes: 7 additions & 24 deletions src/core/src/service_interfaces/StatusHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,18 +836,13 @@ def __try_add_error(error_list, detail):
error_list.insert(0, detail)
return True

def __set_errors_json(self, error_count_by_operation, errors_by_operation, truncated=False):
def __set_errors_json(self, error_count_by_operation, errors_by_operation):
""" Compose the error object json to be added in 'errors' in given operation's summary """
success_code = Constants.PatchOperationTopLevelErrorCode.SUCCESS
error_code = Constants.PatchOperationTopLevelErrorCode.ERROR
error_count = error_count_by_operation
code = success_code if error_count_by_operation == 0 else error_code

# Update the errors json to include truncation detail
if truncated:
error_count += 1 # add 1 because of truncation
code = Constants.PatchOperationTopLevelErrorCode.WARNING if code != error_code else error_code

message = "{0} error/s reported.".format(error_count)
message += " The latest {0} error/s are shared in detail. To view all errors, review this log file on the machine: {1}".format(len(errors_by_operation), self.__log_file_path) if error_count > 0 else ""
return {
Expand Down Expand Up @@ -943,12 +938,12 @@ def __create_truncated_status_file(self, status_file_size_in_bytes, complete_sta
if len(packages_removed_from_assessment) > 0:
# Recompose truncated status file payload (assessment)
truncated_status_file = self.__recompose_truncated_status_file(truncated_status_file=truncated_status_file, truncated_package_list=packages_retained_in_assessment,
count_total_errors=self.__assessment_total_error_count, truncated_substatus_msg=self.__assessment_substatus_msg_copy, substatus_index=assessment_substatus_index)
truncated_substatus_msg=self.__assessment_substatus_msg_copy, substatus_index=assessment_substatus_index)

if len(packages_removed_from_installation) > 0:
# Recompose truncated status file payload (installation)
truncated_status_file = self.__recompose_truncated_status_file(truncated_status_file=truncated_status_file, truncated_package_list=packages_retained_in_installation,
count_total_errors=self.__installation_total_error_count, truncated_substatus_msg=self.__installation_substatus_msg_copy, substatus_index=installation_substatus_index)
truncated_substatus_msg=self.__installation_substatus_msg_copy, substatus_index=installation_substatus_index)

status_file_size_in_bytes, status_file_agent_size_diff = self.__get_new_size_in_bytes_after_truncation(truncated_status_file)
size_of_max_packages_allowed_in_status -= status_file_agent_size_diff # Reduce the max packages byte size by tombstone, new error, and escape chars byte size
Expand Down Expand Up @@ -1088,32 +1083,20 @@ def __get_substatus_index(self, substatus_list_name, substatus_list):

return None

def __recompose_truncated_status_file(self, truncated_status_file, truncated_package_list, count_total_errors, truncated_substatus_msg, substatus_index):
def __recompose_truncated_status_file(self, truncated_status_file, truncated_package_list, truncated_substatus_msg, substatus_index):
""" Recompose final truncated status file version """
truncated_detail_list = []
code, errors_details = self.__get_current_complete_status_errors(substatus_msg=truncated_substatus_msg)
code, _ = self.__get_current_complete_status_errors(substatus_msg=truncated_substatus_msg)

# Check for existing errors before recompose
if code != Constants.PatchOperationTopLevelErrorCode.ERROR:
truncated_status_file['status']['substatus'][substatus_index]['status'] = Constants.STATUS_WARNING.lower() # Update substatus status to warning
else:
truncated_detail_list.extend(errors_details)

truncated_msg_errors = self.__recompose_substatus_msg_errors(truncated_detail_list, count_total_errors) # Recompose substatus msg errors
truncated_substatus_msg = self.__update_substatus_msg(substatus_msg=truncated_substatus_msg, substatus_msg_patches=truncated_package_list, substatus_msg_errors=truncated_msg_errors)
truncated_substatus_msg = self.__update_substatus_msg(substatus_msg=truncated_substatus_msg, substatus_msg_patches=truncated_package_list)

truncated_status_file['status']['substatus'][substatus_index]['formattedMessage']['message'] = json.dumps(truncated_substatus_msg)

return truncated_status_file

def __recompose_substatus_msg_errors(self, truncation_detail_list, count_total_errors):
""" Recompose truncated substatus errors json """
error_msg = Constants.StatusTruncationConfig.TRUNCATION_WARNING_MESSAGE
truncated_error_detail = self.__set_error_detail(Constants.PatchOperationErrorCodes.TRUNCATION, error_msg) # Reuse the errors object set up
self.__try_add_error(truncation_detail_list, truncated_error_detail)
truncated_errors_json = self.__set_errors_json(count_total_errors, truncation_detail_list, True) # True for truncated

return truncated_errors_json

def __update_substatus_msg(self, substatus_msg, substatus_msg_patches, substatus_msg_errors=None):
substatus_msg['patches'] = substatus_msg_patches
if substatus_msg_errors:
Expand Down
Loading

0 comments on commit 061c365

Please sign in to comment.