Skip to content

Commit

Permalink
Refreshing cache with machine source prior to ending execution (#260)
Browse files Browse the repository at this point in the history
* Refreshing cache with machine source prior to ending execution

* Refreshing cache with machine source: Addressing PR feedback #1

* Refreshing cache with machine source: Addressing PR feedback #2
  • Loading branch information
rane-rajasi authored Jun 18, 2024
1 parent e13b551 commit 872702a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/core/src/CoreMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, argv):
stdout_file_mirror = bootstrapper.stdout_file_mirror
telemetry_writer = bootstrapper.telemetry_writer
lifecycle_manager = status_handler = execution_config = None
package_manager = None

# Init operation statuses
patch_operation_requested = Constants.UNKNOWN
Expand Down Expand Up @@ -101,7 +102,6 @@ def __init__(self, argv):
patch_installer.mark_installation_completed()
overall_patch_installation_operation_successful = True
self.update_patch_substatus_if_pending(patch_operation_requested, overall_patch_installation_operation_successful, patch_assessment_successful, configure_patching_successful, status_handler, composite_logger)

except Exception as error:
# Privileged operation handling for non-production use
if Constants.EnvLayer.PRIVILEGED_OP_MARKER in repr(error):
Expand Down Expand Up @@ -134,6 +134,9 @@ def __init__(self, argv):
if status_handler is not None:
status_handler.log_truncated_patches()

if package_manager is not None:
package_manager.refresh_repo_safely()

# clean up temp folder of files created by Core after execution completes
if self.is_temp_folder_available(bootstrapper.env_layer, execution_config):
composite_logger.log_debug("Deleting all files of certain format from temp folder [FileFormat={0}][TempFolderLocation={1}]"
Expand Down
7 changes: 7 additions & 0 deletions src/core/src/package_managers/PackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def refresh_repo(self):
"""Resynchronize the package index files from their sources."""
pass

def refresh_repo_safely(self):
"""Resynchronize the package index files from machine sources."""
try:
self.refresh_repo()
except Exception as error:
self.composite_logger.log_debug("Error in refreshing cache from machine sources. [Error={0}]".format(repr(error)))

# region Get Available Updates
@abstractmethod
def invoke_package_manager_advanced(self, command, raise_on_exception=True):
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/package_managers/ZypperPackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def refresh_repo(self):
self.composite_logger.log_warning("Unable to refresh repo (retries exhausted after reboot).")
raise
else:
self.composite_logger.log_warning("Setting force_reboot flag to True.")
self.composite_logger.log_debug("Setting force_reboot flag to True.")
self.force_reboot = True

def __refresh_repo_services(self):
Expand Down
2 changes: 1 addition & 1 deletion src/core/tests/Test_CoreMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def test_assessment_operation_fail(self):
self.assertEqual(len(substatus_file_data), 2)
self.assertTrue(substatus_file_data[0]["name"] == Constants.PATCH_ASSESSMENT_SUMMARY)
self.assertTrue(substatus_file_data[0]["status"].lower() == Constants.STATUS_ERROR.lower())
self.assertEqual(len(json.loads(substatus_file_data[0]["formattedMessage"]["message"])["errors"]["details"]), 2)
self.assertEqual(len(json.loads(substatus_file_data[0]["formattedMessage"]["message"])["errors"]["details"]), 3)
self.assertTrue(substatus_file_data[1]["name"] == Constants.CONFIGURE_PATCHING_SUMMARY)
self.assertTrue(substatus_file_data[1]["status"].lower() == Constants.STATUS_SUCCESS.lower())
runtime.stop()
Expand Down

0 comments on commit 872702a

Please sign in to comment.