Skip to content

Commit

Permalink
Merge pull request #173 from Azure/garamrak-updateVariableNames
Browse files Browse the repository at this point in the history
Update variable names and call different function to get package manager name
  • Loading branch information
GAURAVRAMRAKHYANI authored Feb 27, 2023
2 parents 006d225 + 82dd3f1 commit 938ab4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/core/src/bootstrap/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class PerfLogTrackerParams:
TASK = "task"
TASK_STATUS = "task_status"
PACKAGE_MANAGER = "package_manager"
NUMBER_OF_TRIALS = "number_of_trials"
RETRY_COUNT = "retry_count"
ERROR_MSG = "error_msg"
INSTALLED_PATCH_COUNT = "installed_patch_count"
PATCH_OPERATION_SUCCESSFUL = "patch_operation_successful"
Expand Down
14 changes: 7 additions & 7 deletions src/core/src/core_logic/PatchAssessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, env_layer, execution_config, composite_logger, telemetry_writ
self.status_handler = status_handler
self.lifecycle_manager = lifecycle_manager
self.package_manager = package_manager
self.package_manager_name = self.package_manager.__class__.__name__
self.package_manager_name = self.package_manager.get_package_manager_setting(Constants.PKG_MGR_SETTING_IDENTITY)
self.assessment_state_file_path = os.path.join(self.execution_config.config_folder, Constants.ASSESSMENT_STATE_FILE)

def start_assessment(self):
Expand All @@ -62,13 +62,13 @@ def start_assessment(self):
self.composite_logger.log("\n\nGetting available patches...")
self.package_manager.refresh_repo()
self.status_handler.reset_assessment_data()
number_of_tries = 0
retry_count = 0

for i in range(0, Constants.MAX_ASSESSMENT_RETRY_COUNT):
try:
if self.lifecycle_manager is not None:
self.lifecycle_manager.lifecycle_status_check() # may terminate the code abruptly, as designed
number_of_tries = number_of_tries + 1
retry_count = retry_count + 1
packages, package_versions = self.package_manager.get_all_updates()
self.telemetry_writer.write_event("Full assessment: " + str(packages), Constants.TelemetryEventLevel.Verbose)
self.status_handler.set_package_assessment_status(packages, package_versions)
Expand All @@ -88,21 +88,21 @@ def start_assessment(self):
else:
error_msg = 'Error retrieving available patches: ' + repr(error)
self.composite_logger.log_error(error_msg)
self.write_assessment_perf_logs(number_of_tries, Constants.TaskStatus.FAILED, error_msg)
self.write_assessment_perf_logs(retry_count, Constants.TaskStatus.FAILED, error_msg)
self.status_handler.add_error_to_status(error_msg, Constants.PatchOperationErrorCodes.DEFAULT_ERROR)
if Constants.ERROR_ADDED_TO_STATUS not in repr(error):
error.args = (error.args, "[{0}]".format(Constants.ERROR_ADDED_TO_STATUS))
self.status_handler.set_assessment_substatus_json(status=Constants.STATUS_ERROR)
raise

self.write_assessment_perf_logs(number_of_tries, Constants.TaskStatus.SUCCEEDED, "")
self.write_assessment_perf_logs(retry_count, Constants.TaskStatus.SUCCEEDED, "")
self.composite_logger.log("\nPatch assessment completed.\n")
return True

def write_assessment_perf_logs(self, number_of_tries, task_status, error_msg):
def write_assessment_perf_logs(self, retry_count, task_status, error_msg):
assessment_perf_log = {Constants.PerfLogTrackerParams.TASK: Constants.ASSESSMENT, Constants.PerfLogTrackerParams.TASK_STATUS: str(task_status),
Constants.PerfLogTrackerParams.ERROR_MSG: error_msg, Constants.PerfLogTrackerParams.PACKAGE_MANAGER: self.package_manager_name,
Constants.PerfLogTrackerParams.NUMBER_OF_TRIALS: str(number_of_tries)}
Constants.PerfLogTrackerParams.RETRY_COUNT: str(retry_count)}
self.stopwatch.stop_and_write_telemetry(str(assessment_perf_log))

def raise_if_telemetry_unsupported(self):
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/core_logic/PatchInstaller.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __init__(self, env_layer, execution_config, composite_logger, telemetry_writ
self.lifecycle_manager = lifecycle_manager

self.package_manager = package_manager
self.package_manager_name = self.package_manager.__class__.__name__
self.package_manager_name = self.package_manager.get_package_manager_setting(Constants.PKG_MGR_SETTING_IDENTITY)
self.package_filter = package_filter
self.maintenance_window = maintenance_window
self.reboot_manager = reboot_manager
Expand Down Expand Up @@ -106,7 +106,7 @@ def start_installation(self, simulate=False):

return overall_patch_installation_successful

def write_installer_perf_logs(self, patch_operation_successful, installed_patch_count, number_of_rounds, maintenance_window, maintenance_window_exceeded, task_status, error_msg):
def write_installer_perf_logs(self, patch_operation_successful, installed_patch_count, retry_count, maintenance_window, maintenance_window_exceeded, task_status, error_msg):
perc_maintenance_window_used = -1

try:
Expand All @@ -116,7 +116,7 @@ def write_installer_perf_logs(self, patch_operation_successful, installed_patch_

patch_installation_perf_log = {Constants.PerfLogTrackerParams.TASK: Constants.INSTALLATION, Constants.PerfLogTrackerParams.TASK_STATUS: str(task_status), Constants.PerfLogTrackerParams.ERROR_MSG: error_msg,
Constants.PerfLogTrackerParams.PACKAGE_MANAGER: self.package_manager_name, Constants.PerfLogTrackerParams.PATCH_OPERATION_SUCCESSFUL: str(patch_operation_successful),
Constants.PerfLogTrackerParams.INSTALLED_PATCH_COUNT: str(installed_patch_count), Constants.PerfLogTrackerParams.NUMBER_OF_TRIALS: str(number_of_rounds),
Constants.PerfLogTrackerParams.INSTALLED_PATCH_COUNT: str(installed_patch_count), Constants.PerfLogTrackerParams.RETRY_COUNT: str(retry_count),
Constants.PerfLogTrackerParams.MAINTENANCE_WINDOW: str(maintenance_window.duration), Constants.PerfLogTrackerParams.PERC_MAINTENANCE_WINDOW_USED: str(perc_maintenance_window_used),
Constants.PerfLogTrackerParams.MAINTENANCE_WINDOW_EXCEEDED: str(maintenance_window_exceeded)}
self.stopwatch.stop_and_write_telemetry(str(patch_installation_perf_log))
Expand Down

0 comments on commit 938ab4c

Please sign in to comment.