Skip to content

Commit e025e1f

Browse files
committed
add pr 314 changes
1 parent 0a80cc6 commit e025e1f

File tree

3 files changed

+10
-21
lines changed

3 files changed

+10
-21
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: 4 additions & 12 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
@@ -827,19 +825,13 @@ def __send_metadata_to_health_store(self):
827825
# region - Failed packages retry succeeded
828826
def log_final_installation_metric(self, patch_installation_successful, maintenance_window_exceeded, maintenance_window, installed_update_count):
829827
""" log final installation operation status. """
830-
warning_status = self.__check_installation_status_can_set_to_warning(patch_installation_successful, maintenance_window_exceeded)
828+
warning_status = self.should_patch_installation_status_be_set_to_warning(patch_installation_successful, maintenance_window_exceeded)
831829
if warning_status:
832830
self.log_final_warning_metric(maintenance_window, installed_update_count)
833831
else:
834832
self.log_final_metrics(maintenance_window, patch_installation_successful, maintenance_window_exceeded, installed_update_count)
835833

836-
def __check_installation_status_can_set_to_warning(self, patch_installation_successful, maintenance_window_exceeded):
834+
def should_patch_installation_status_be_set_to_warning(self, patch_installation_successful, maintenance_window_exceeded):
837835
""" 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.are_all_requested_packages_installed()
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
836+
return not patch_installation_successful and not maintenance_window_exceeded and self.status_handler.are_all_requested_packages_installed()
845837
# endregion

src/core/tests/Test_CoreMain.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def mock_batch_patching_with_no_packages(self, all_packages, all_package_version
6464
"""Mock batch_patching to simulate package installation failure, return no packages"""
6565
return [], [], 0, False
6666

67-
def mock_check_all_requested_packages_install_state(self):
67+
def mock_are_all_requested_packages_installed(self):
6868
return True
6969

7070
def test_operation_fail_for_non_autopatching_request(self):
@@ -1332,11 +1332,11 @@ def test_warning_status_when_packages_initially_fail_but_succeed_on_retry_no_bat
13321332

13331333
# Store original methods
13341334
original_batch_patching = runtime.patch_installer.batch_patching
1335-
original_check_all_requested_packages_install_state= runtime.status_handler.are_all_requested_packages_installed
1335+
original_check_all_requested_packages_install_state = runtime.status_handler.are_all_requested_packages_installed
13361336

13371337
# Mock batch_patching with packages to return [], [], false
13381338
runtime.patch_installer.batch_patching = self.mock_batch_patching_with_no_packages
1339-
runtime.status_handler.are_all_requested_packages_installed = self.mock_check_all_requested_packages_install_state
1339+
runtime.status_handler.are_all_requested_packages_installed = self.mock_are_all_requested_packages_installed
13401340

13411341
# Run CoreMain to execute the installation
13421342
try:
@@ -1346,7 +1346,7 @@ def test_warning_status_when_packages_initially_fail_but_succeed_on_retry_no_bat
13461346
finally:
13471347
# reset mock
13481348
runtime.patch_installer.batch_patching = original_batch_patching
1349-
runtime.status_handler.get_installation_packages_list = original_check_all_requested_packages_install_state
1349+
runtime.status_handler.are_all_requested_packages_installed = original_check_all_requested_packages_install_state
13501350
runtime.stop()
13511351

13521352
def __check_telemetry_events(self, runtime):
@@ -1363,9 +1363,6 @@ def __assertion_pkg_succeed_on_retry(self, runtime):
13631363
# Check telemetry events
13641364
self.__check_telemetry_events(runtime)
13651365

1366-
# If true, set installation status to warning
1367-
self.assertTrue(runtime.patch_installer.set_patch_installation_status_to_warning_from_failed())
1368-
13691366
# Check status file
13701367
with runtime.env_layer.file_system.open(runtime.execution_config.status_file_path, 'r') as file_handle:
13711368
substatus_file_data = json.load(file_handle)[0]["status"]["substatus"]

0 commit comments

Comments
 (0)