Skip to content

Commit f9ae07e

Browse files
committed
PR feedback explanation
1 parent 7d909f0 commit f9ae07e

File tree

4 files changed

+26
-35
lines changed

4 files changed

+26
-35
lines changed

src/core/src/CoreMain.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ def __init__(self, argv):
9393
# setting current operation here, to include patch_installer init within installation actions, ensuring any exceptions during patch_installer init are added in installation summary errors object
9494
status_handler.set_current_operation(Constants.INSTALLATION)
9595
patch_installer = container.get('patch_installer')
96-
patch_installation_successful = patch_installer.start_installation()
96+
patch_installation_successful, maintenance_window_exceeded = patch_installer.start_installation()
9797
patch_assessment_successful = False
9898
patch_assessment_successful = patch_assessor.start_assessment()
9999

100100
# PatchInstallationSummary to be marked as completed successfully only after the implicit (i.e. 2nd) assessment is completed, as per CRP's restrictions
101101
if patch_assessment_successful and patch_installation_successful:
102102
patch_installer.mark_installation_completed()
103103
overall_patch_installation_operation_successful = True
104-
elif patch_installer.set_patch_installation_status_to_warning_from_failed():
104+
elif patch_installer.should_patch_installation_status_be_set_to_warning(patch_installation_successful, maintenance_window_exceeded):
105105
patch_installer.mark_installation_completed_with_warning()
106106
overall_patch_installation_operation_successful = True
107107
self.update_patch_substatus_if_pending(patch_operation_requested, overall_patch_installation_operation_successful, patch_assessment_successful, configure_patching_successful, status_handler, composite_logger)

src/core/src/core_logic/PatchInstaller.py

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ def __init__(self, env_layer, execution_config, composite_logger, telemetry_writ
5353

5454
self.stopwatch = Stopwatch(self.env_layer, self.telemetry_writer, self.composite_logger)
5555

56-
self.__enable_installation_status_to_warning_flag = False
57-
5856
def start_installation(self, simulate=False):
5957
""" Kick off a patch installation run """
6058
self.status_handler.set_current_operation(Constants.INSTALLATION)
@@ -126,7 +124,7 @@ def start_installation(self, simulate=False):
126124
overall_patch_installation_successful = bool(update_run_successful and not maintenance_window_exceeded)
127125
# NOTE: Not updating installation substatus at this point because we need to wait for the implicit/second assessment to complete first, as per CRP's instructions
128126

129-
return overall_patch_installation_successful
127+
return overall_patch_installation_successful, maintenance_window_exceeded
130128

131129
def write_installer_perf_logs(self, patch_operation_successful, installed_patch_count, retry_count, maintenance_window, maintenance_window_exceeded, task_status, error_msg):
132130
perc_maintenance_window_used = -1
@@ -284,7 +282,7 @@ def install_updates(self, maintenance_window, package_manager, simulate=False):
284282
successful_parent_package_install_count_in_batch_patching = self.successful_parent_package_install_count
285283

286284
if len(packages) == 0:
287-
self.log_final_installation_metric(patch_installation_successful, maintenance_window_exceeded, maintenance_window, installed_update_count)
285+
self.log_final_metrics(maintenance_window, patch_installation_successful, maintenance_window_exceeded, installed_update_count)
288286
return installed_update_count, patch_installation_successful, maintenance_window_exceeded
289287
else:
290288
progress_status = self.progress_template.format(str(datetime.timedelta(minutes=maintenance_window.get_remaining_time_in_minutes())), str(self.attempted_parent_package_install_count), str(self.successful_parent_package_install_count), str(self.failed_parent_package_install_count), str(installed_update_count - self.successful_parent_package_install_count),
@@ -383,7 +381,7 @@ def install_updates(self, maintenance_window, package_manager, simulate=False):
383381
self.composite_logger.log_debug("\nPerforming final system state reconciliation...")
384382
installed_update_count += self.perform_status_reconciliation_conditionally(package_manager, True)
385383

386-
self.log_final_installation_metric(patch_installation_successful, maintenance_window_exceeded, maintenance_window, installed_update_count)
384+
self.log_final_metrics(maintenance_window, patch_installation_successful, maintenance_window_exceeded, installed_update_count)
387385

388386
install_update_count_in_sequential_patching = installed_update_count - install_update_count_in_batch_patching
389387
attempted_parent_package_install_count_in_sequential_patching = self.attempted_parent_package_install_count - attempted_parent_package_install_count_in_batch_patching
@@ -420,7 +418,6 @@ def log_final_metrics(self, maintenance_window, patch_installation_successful, m
420418

421419
def log_final_warning_metric(self, maintenance_window, installed_update_count):
422420
""" Log the final metrics for warning installation status. """
423-
424421
self.__log_progress_status(maintenance_window, installed_update_count)
425422
message = "All requested package(s) are installed. Any patch errors marked are from previous attempts."
426423
self.status_handler.add_error_to_status(message, Constants.PatchOperationErrorCodes.PACKAGES_RETRY_SUCCEEDED)
@@ -692,9 +689,12 @@ def mark_installation_completed(self):
692689

693690
def mark_installation_completed_with_warning(self):
694691
""" Marks Installation operation as warning by updating the status of PatchInstallationSummary as warning and patch metadata to be sent to healthstore.
695-
This is set outside of start_installation function to a restriction in CRP, where installation substatus should be marked as warning only after the implicit (2nd) assessment operation
696-
and all supposed packages are installed as expected. """
692+
This is set outside of start_installation function due to a restriction in CRP, where installation substatus should be marked as warning only after the implicit (2nd) assessment operation
693+
and all customer requested packages are installed. """
697694

695+
message = "All requested package(s) are installed. Any patch errors marked are from previous attempts."
696+
self.composite_logger.log_error(message)
697+
self.status_handler.add_error_to_status(message, Constants.PatchOperationErrorCodes.PACKAGES_RETRY_SUCCEEDED)
698698
self.status_handler.set_installation_substatus_json(status=Constants.STATUS_WARNING)
699699

700700
# Update patch metadata in status for auto patching request, to be reported to healthStore
@@ -812,7 +812,11 @@ def get_max_batch_size(self, maintenance_window, package_manager):
812812
return max_batch_size_for_packages
813813

814814
def __log_progress_status(self, maintenance_window, installed_update_count):
815-
progress_status = self.progress_template.format(str(datetime.timedelta(minutes=maintenance_window.get_remaining_time_in_minutes())), str(self.attempted_parent_package_install_count), str(self.successful_parent_package_install_count), str(self.failed_parent_package_install_count), str(installed_update_count - self.successful_parent_package_install_count),
815+
progress_status = self.progress_template.format(str(datetime.timedelta(minutes=maintenance_window.get_remaining_time_in_minutes())),
816+
str(self.attempted_parent_package_install_count),
817+
str(self.successful_parent_package_install_count),
818+
str(self.failed_parent_package_install_count),
819+
str(installed_update_count - self.successful_parent_package_install_count),
816820
"Completed processing packages!")
817821
self.composite_logger.log(progress_status)
818822

@@ -824,22 +828,5 @@ def __send_metadata_to_health_store(self):
824828
report_to_healthstore=True,
825829
wait_after_update=False)
826830

827-
# region - Failed packages retry succeeded
828-
def log_final_installation_metric(self, patch_installation_successful, maintenance_window_exceeded, maintenance_window, installed_update_count):
829-
""" log final installation operation status. """
830-
warning_status = self.__check_installation_status_can_set_to_warning(patch_installation_successful, maintenance_window_exceeded)
831-
if warning_status:
832-
self.log_final_warning_metric(maintenance_window, installed_update_count)
833-
else:
834-
self.log_final_metrics(maintenance_window, patch_installation_successful, maintenance_window_exceeded, installed_update_count)
835-
836-
def __check_installation_status_can_set_to_warning(self, patch_installation_successful, maintenance_window_exceeded):
837-
""" Verify patch installation status can be set to warning from failed. """
838-
# type (bool, bool) -> bool
839-
self.__enable_installation_status_to_warning_flag = not patch_installation_successful and not maintenance_window_exceeded and self.status_handler.check_all_requested_packages_install_state()
840-
return self.__enable_installation_status_to_warning_flag
841-
842-
def set_patch_installation_status_to_warning_from_failed(self):
843-
"""Access enable_installation_warning_status value"""
844-
return self.__enable_installation_status_to_warning_flag
845-
# endregion
831+
def should_patch_installation_status_be_set_to_warning(self, patch_installation_successful, maintenance_window_exceeded):
832+
return not patch_installation_successful and not maintenance_window_exceeded and self.status_handler.are_all_requested_packgaes_installed()

src/core/src/service_interfaces/StatusHandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def get_os_name_and_version(self):
263263
self.composite_logger.log_error("Unable to determine platform information: {0}".format(repr(error)))
264264
return "unknownDist_unknownVer"
265265

266-
def check_all_requested_packages_install_state(self):
266+
def are_all_requested_packgaes_installed(self):
267267
# type (none) -> bool
268268
""" Check if all requested package(s) are installed. """
269269

src/core/tests/Test_PatchInstaller.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ def test_patch_installer_for_azgps_coordinated(self):
241241
argument_composer.maximum_duration = "PT30M"
242242
runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.APT)
243243
runtime.set_legacy_test_type('HappyPath')
244-
self.assertFalse(runtime.patch_installer.start_installation()) # failure is in unrelated patch installation batch processing
244+
patch_installation_successful, maintenance_window_exceeded = runtime.patch_installer.start_installation()
245+
self.assertFalse(patch_installation_successful) # failure is in unrelated patch installation batch processing
245246
self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z")
246247
self.assertEqual(runtime.package_manager.max_patch_publish_date, "") # reason: not enough time to use
247248

@@ -253,21 +254,24 @@ def test_patch_installer_for_azgps_coordinated(self):
253254
runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.APT)
254255
runtime.set_legacy_test_type('HappyPath')
255256
runtime.package_manager.install_security_updates_azgps_coordinated = lambda: (1, "Failed")
256-
self.assertFalse(runtime.patch_installer.start_installation())
257+
patch_installation_successful, maintenance_window_exceeded = runtime.patch_installer.start_installation()
258+
self.assertFalse(patch_installation_successful)
257259
self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z")
258260
self.assertEqual(runtime.package_manager.max_patch_publish_date, "") # reason: the strict SDP is forced to fail with the lambda above
259261
runtime.stop()
260262

261263
runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM)
262264
runtime.set_legacy_test_type('HappyPath')
263-
self.assertTrue(runtime.patch_installer.start_installation())
265+
patch_installation_successful, maintenance_window_exceeded = runtime.patch_installer.start_installation()
266+
self.assertTrue(patch_installation_successful)
264267
self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z")
265268
self.assertEqual(runtime.package_manager.max_patch_publish_date, "") # unsupported in Yum
266269
runtime.stop()
267270

268271
runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.ZYPPER)
269272
runtime.set_legacy_test_type('HappyPath')
270-
self.assertFalse(runtime.patch_installer.start_installation()) # failure is in unrelated patch installation batch processing
273+
patch_installation_successful, maintenance_window_exceeded = runtime.patch_installer.start_installation()
274+
self.assertFalse(patch_installation_successful) # failure is in unrelated patch installation batch processing
271275
self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z")
272276
self.assertEqual(runtime.package_manager.max_patch_publish_date, "") # unsupported in Zypper
273277
runtime.stop()

0 commit comments

Comments
 (0)