diff --git a/src/core/src/bootstrap/Constants.py b/src/core/src/bootstrap/Constants.py index ae1ce50a..123a430b 100644 --- a/src/core/src/bootstrap/Constants.py +++ b/src/core/src/bootstrap/Constants.py @@ -30,7 +30,7 @@ def __iter__(self): UNKNOWN = "Unknown" # Extension version (todo: move to a different file) - EXT_VERSION = "1.6.25" + EXT_VERSION = "1.6.26" # Runtime environments TEST = 'Test' @@ -156,7 +156,7 @@ class AutoAssessmentStates(EnumBackport): UNKNOWN_PACKAGE_SIZE = "Unknown" PACKAGE_STATUS_REFRESH_RATE_IN_SECONDS = 10 - MAX_FILE_OPERATION_RETRY_COUNT = 10 + MAX_FILE_OPERATION_RETRY_COUNT = 5 MAX_ASSESSMENT_RETRY_COUNT = 5 MAX_INSTALLATION_RETRY_COUNT = 3 MAX_IMDS_CONNECTION_RETRY_COUNT = 5 diff --git a/src/core/src/bootstrap/EnvLayer.py b/src/core/src/bootstrap/EnvLayer.py index 5a653d72..e5c433df 100644 --- a/src/core/src/bootstrap/EnvLayer.py +++ b/src/core/src/bootstrap/EnvLayer.py @@ -281,7 +281,7 @@ def open(self, file_path, mode): try: return open(real_path, mode) except Exception as error: - if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT - 1: + if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT: time.sleep(i + 1) else: raise Exception("Unable to open {0} (retries exhausted). Error: {1}.".format(str(real_path), repr(error))) @@ -310,7 +310,7 @@ def read_with_retry(self, file_path_or_handle): self.__write_record(operation, code=0, output=value, delay=0) return value except Exception as error: - if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT - 1: + if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT: time.sleep(i + 1) else: raise Exception("Unable to read from {0} (retries exhausted). Error: {1}.".format(str(file_path_or_handle), repr(error))) @@ -327,7 +327,7 @@ def write_with_retry(self, file_path_or_handle, data, mode='a+'): file_handle.write(str(data)) break except Exception as error: - if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT - 1: + if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT: time.sleep(i + 1) else: raise Exception("Unable to write to {0} (retries exhausted). Error: {1}.".format(str(file_handle.name), repr(error))) @@ -346,7 +346,7 @@ def write_with_retry_using_temp_file(file_path, data, mode='w'): shutil.move(tempname, file_path) break except Exception as error: - if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT - 1: + if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT: time.sleep(i + 1) else: raise Exception("Unable to write to {0} (retries exhausted). Error: {1}.".format(str(file_path), repr(error))) diff --git a/src/core/src/core_logic/PatchAssessor.py b/src/core/src/core_logic/PatchAssessor.py index 192f172a..de1cac7d 100644 --- a/src/core/src/core_logic/PatchAssessor.py +++ b/src/core/src/core_logic/PatchAssessor.py @@ -62,7 +62,7 @@ def start_assessment(self): self.status_handler.set_assessment_substatus_json(status=Constants.STATUS_SUCCESS) break except Exception as error: - if i < Constants.MAX_ASSESSMENT_RETRY_COUNT - 1: + if i < Constants.MAX_ASSESSMENT_RETRY_COUNT: error_msg = 'Retryable error retrieving available patches: ' + repr(error) self.composite_logger.log_warning(error_msg) self.status_handler.add_error_to_status(error_msg, Constants.PatchOperationErrorCodes.DEFAULT_ERROR) diff --git a/src/core/src/service_interfaces/LifecycleManager.py b/src/core/src/service_interfaces/LifecycleManager.py index 931f886a..daac1ed0 100644 --- a/src/core/src/service_interfaces/LifecycleManager.py +++ b/src/core/src/service_interfaces/LifecycleManager.py @@ -56,7 +56,7 @@ def read_extension_sequence(self): with self.env_layer.file_system.open(self.ext_state_file_path, mode="r") as file_handle: return json.load(file_handle)['extensionSequence'] except Exception as error: - if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT - 1: + if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT: self.composite_logger.log_warning("Exception on extension sequence read. [Exception={0}] [RetryCount={1}]".format(repr(error), str(i))) time.sleep(i+1) else: @@ -115,7 +115,7 @@ def read_core_sequence(self): return core_sequence except Exception as error: - if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT - 1: + if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT: self.composite_logger.log_warning("Exception on core sequence read. [Exception={0}] [RetryCount={1}]".format(repr(error), str(i))) time.sleep(i + 1) else: @@ -145,7 +145,7 @@ def update_core_sequence(self, completed=False): with self.env_layer.file_system.open(self.core_state_file_path, 'w+') as file_handle: file_handle.write(core_state_payload) except Exception as error: - if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT - 1: + if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT: self.composite_logger.log_warning("Exception on core sequence update. [Exception={0}] [RetryCount={1}]".format(repr(error), str(i))) time.sleep(i + 1) else: diff --git a/src/core/src/service_interfaces/StatusHandler.py b/src/core/src/service_interfaces/StatusHandler.py index 700b7e79..88b352cf 100644 --- a/src/core/src/service_interfaces/StatusHandler.py +++ b/src/core/src/service_interfaces/StatusHandler.py @@ -501,7 +501,7 @@ def __load_status_file_components(self, initial_load=False): with self.env_layer.file_system.open(self.status_file_path, 'r') as file_handle: status_file_data_raw = json.load(file_handle)[0] # structure is array of 1 except Exception as error: - if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT - 1: + if i < Constants.MAX_FILE_OPERATION_RETRY_COUNT: time.sleep(i + 1) else: self.composite_logger.log_error("Unable to read status file (retries exhausted). Error: {0}.".format(repr(error))) diff --git a/src/core/tests/Test_LifecycleManagerArc.py b/src/core/tests/Test_LifecycleManagerArc.py index 35455437..65806f8a 100644 --- a/src/core/tests/Test_LifecycleManagerArc.py +++ b/src/core/tests/Test_LifecycleManagerArc.py @@ -54,7 +54,8 @@ def test_read_extension_sequence_fail(self): # file open throws exception self.lifecycle_manager.ext_state_file_path = old_ext_state_file_path self.runtime.env_layer.file_system.open = self.mock_file_open_throw_exception - self.assertRaises(Exception, self.lifecycle_manager.read_extension_sequence) + ext_state_json = self.lifecycle_manager.read_extension_sequence() + self.assertEquals(ext_state_json, None) def test_read_extension_sequence_success(self): ext_state_json = self.lifecycle_manager.read_extension_sequence() @@ -64,7 +65,8 @@ def test_read_extension_sequence_success(self): def test_read_core_sequence_fail(self): # file open throws exception self.runtime.env_layer.file_system.open = self.mock_file_open_throw_exception - self.assertRaises(Exception, self.lifecycle_manager.read_core_sequence) + core_sequence_json = self.lifecycle_manager.read_core_sequence() + self.assertEquals(core_sequence_json, None) def test_read_core_sequence_success(self): old_core_state_file_path = self.lifecycle_manager.core_state_file_path diff --git a/src/core/tests/Test_LifecycleManagerAzure.py b/src/core/tests/Test_LifecycleManagerAzure.py index cb171f81..f951281e 100644 --- a/src/core/tests/Test_LifecycleManagerAzure.py +++ b/src/core/tests/Test_LifecycleManagerAzure.py @@ -51,7 +51,8 @@ def test_read_extension_sequence_fail(self): # file open throws exception self.lifecycle_manager.ext_state_file_path = old_ext_state_file_path self.runtime.env_layer.file_system.open = self.mock_file_open_throw_exception - self.assertRaises(Exception, self.lifecycle_manager.read_extension_sequence) + ext_state_json = self.lifecycle_manager.read_extension_sequence() + self.assertEquals(ext_state_json, None) def test_read_extension_sequence_success(self): ext_state_json = self.lifecycle_manager.read_extension_sequence() @@ -61,7 +62,8 @@ def test_read_extension_sequence_success(self): def test_read_core_sequence_fail(self): # file open throws exception self.runtime.env_layer.file_system.open = self.mock_file_open_throw_exception - self.assertRaises(Exception, self.lifecycle_manager.read_core_sequence) + core_sequence_json = self.lifecycle_manager.read_core_sequence() + self.assertEquals(core_sequence_json, None) def test_read_core_sequence_success(self): old_core_state_file_path = self.lifecycle_manager.core_state_file_path diff --git a/src/core/tests/Test_PatchAssessor.py b/src/core/tests/Test_PatchAssessor.py index 4a527691..46b943e8 100644 --- a/src/core/tests/Test_PatchAssessor.py +++ b/src/core/tests/Test_PatchAssessor.py @@ -46,7 +46,7 @@ def test_get_all_security_updates_fail(self): def test_assessment_fail_with_status_update(self): self.runtime.package_manager.refresh_repo = self.mock_refresh_repo self.runtime.set_legacy_test_type('UnalignedPath') - self.assertRaises(Exception, self.runtime.patch_assessor.start_assessment) + self.runtime.patch_assessor.start_assessment() with open(self.runtime.execution_config.status_file_path, 'r') as file_handle: file_contents = json.loads(file_handle.read()) self.assertTrue('Unexpected return code (100) from package manager on command: LANG=en_US.UTF8 sudo apt-get -s dist-upgrade' in str(file_contents)) diff --git a/src/extension/src/ActionHandler.py b/src/extension/src/ActionHandler.py index 4c6eeda3..45a1bcc7 100644 --- a/src/extension/src/ActionHandler.py +++ b/src/extension/src/ActionHandler.py @@ -190,7 +190,7 @@ def copy_config_files(self, src, dst, raise_if_not_copied=False): shutil.copy(file_to_copy, dst) break except Exception as error: - if i < Constants.MAX_IO_RETRIES - 1: + if i < Constants.MAX_IO_RETRIES: time.sleep(i + 1) else: error_msg = "Failed to copy file after {0} tries. [Source={1}] [Destination={2}] [Exception={3}]".format(Constants.MAX_IO_RETRIES, str(file_to_copy), str(dst), repr(error)) diff --git a/src/extension/src/Constants.py b/src/extension/src/Constants.py index c9134ead..4a3f6fb8 100644 --- a/src/extension/src/Constants.py +++ b/src/extension/src/Constants.py @@ -28,7 +28,7 @@ def __iter__(self): yield item # Extension version (todo: move to a different file) - EXT_VERSION = "1.6.25" + EXT_VERSION = "1.6.26" # Runtime environments TEST = 'Test' @@ -85,7 +85,7 @@ class TelemetryEventLevel(EnumBackport): UTC_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" # Re-try limit for file operations - MAX_IO_RETRIES = 10 + MAX_IO_RETRIES = 5 # Re-try limit for verifying core process has started successfully MAX_PROCESS_STATUS_CHECK_RETRIES = 5 diff --git a/src/extension/src/EnvLayer.py b/src/extension/src/EnvLayer.py index 22403ca6..168061d9 100644 --- a/src/extension/src/EnvLayer.py +++ b/src/extension/src/EnvLayer.py @@ -202,7 +202,7 @@ def open(self, file_path, mode): try: return open(file_path, mode) except Exception as error: - if i < self.retry_count - 1: + if i < self.retry_count: time.sleep(i + 1) else: raise Exception("Unable to open {0} (retries exhausted). Error: {1}.".format(str(file_path), repr(error))) @@ -236,7 +236,7 @@ def write_with_retry(self, file_path_or_handle, data, mode='a+'): file_handle.write(str(data)) break except Exception as error: - if i < self.retry_count - 1: + if i < self.retry_count: time.sleep(i + 1) else: raise Exception("Unable to write to {0} (retries exhausted). Error: {1}.".format(str(file_handle.name), repr(error))) diff --git a/src/extension/src/manifest.xml b/src/extension/src/manifest.xml index d9adb51d..b7dd95e4 100644 --- a/src/extension/src/manifest.xml +++ b/src/extension/src/manifest.xml @@ -2,7 +2,7 @@ Microsoft.CPlat.Core LinuxPatchExtension - 1.6.25 + 1.6.26 VmRole