Skip to content

Commit

Permalink
Revert off by one fix and update version to 1.6.26 (#94)
Browse files Browse the repository at this point in the history
* Revert off by one fix

* Update version

Co-authored-by: benank <[email protected]>
  • Loading branch information
benank and benank authored Sep 23, 2021
1 parent e875112 commit 3e68b1b
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/core/src/bootstrap/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/core/src/bootstrap/EnvLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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)))
Expand All @@ -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)))
Expand All @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/core_logic/PatchAssessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/service_interfaces/LifecycleManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/service_interfaces/StatusHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
6 changes: 4 additions & 2 deletions src/core/tests/Test_LifecycleManagerArc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/core/tests/Test_LifecycleManagerAzure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/Test_PatchAssessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/extension/src/ActionHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/extension/src/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/extension/src/EnvLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion src/extension/src/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ExtensionImage xmlns="http://schemas.microsoft.com/windowsazure">
<ProviderNameSpace>Microsoft.CPlat.Core</ProviderNameSpace>
<Type>LinuxPatchExtension</Type>
<Version>1.6.25</Version>
<Version>1.6.26</Version>
<Label>Microsoft Azure VM InGuest Patch Extension for Linux Virtual Machines</Label>
<HostingResources>VmRole</HostingResources>
<MediaLink></MediaLink>
Expand Down

0 comments on commit 3e68b1b

Please sign in to comment.