Skip to content

Commit

Permalink
APT: Patch Mode set to disabled in ConfigurePatching when os patch co…
Browse files Browse the repository at this point in the history
…nfig file does not exist
  • Loading branch information
rane-rajasi committed Sep 6, 2023
1 parent 3d68c37 commit 8f6b743
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/src/package_managers/AptitudePackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,9 @@ def get_package_size(self, output):
def get_current_auto_os_patch_state(self):
""" Gets the current auto OS update patch state on the machine """
self.composite_logger.log("Fetching the current automatic OS patch state on the machine...")
self.__get_current_auto_os_updates_setting_on_machine()
if int(self.unattended_upgrade_value) == 0:
if os.path.exists(self.os_patch_configuration_settings_file_path):
self.__get_current_auto_os_updates_setting_on_machine()
if not os.path.exists(self.os_patch_configuration_settings_file_path) or int(self.unattended_upgrade_value) == 0:
current_auto_os_patch_state = Constants.AutomaticOSPatchStates.DISABLED
elif int(self.unattended_upgrade_value) == 1:
current_auto_os_patch_state = Constants.AutomaticOSPatchStates.ENABLED
Expand Down
9 changes: 9 additions & 0 deletions src/core/tests/Test_AptitudePackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ def test_disable_auto_os_update_with_one_patch_mode_enabled_success(self):
self.assertTrue('APT::Periodic::Update-Package-Lists "0"' in os_patch_configuration_settings)
self.assertTrue('APT::Periodic::Unattended-Upgrade "0"' in os_patch_configuration_settings)

def test_get_current_auto_os_updates_with_no_os_patch_configuration_settings_file(self):
# os_patch_configuration_settings_file does not exist, hence current os patch state is marked as Disabled
package_manager = self.container.get('package_manager')
package_manager.get_current_auto_os_patch_state = self.runtime.backup_get_current_auto_os_patch_state

self.assertTrue(package_manager.get_current_auto_os_patch_state() == Constants.AutomaticOSPatchStates.DISABLED)

package_manager.get_current_auto_os_patch_state = self.runtime.get_current_auto_os_patch_state

def test_disable_auto_os_update_failure(self):
# disable with non existing log file
package_manager = self.container.get('package_manager')
Expand Down
28 changes: 28 additions & 0 deletions src/core/tests/Test_ConfigurePatchingProcessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,34 @@ def test_configure_patching_with_patch_mode_and_assessment_mode_by_platform(self
# stop test runtime
runtime.stop()

def test_patch_mode_disabled_for_configure_patching_with_no_os_patch_configuration_settings_file(self):
argument_composer = ArgumentComposer()
argument_composer.operation = Constants.CONFIGURE_PATCHING
argument_composer.patch_mode = Constants.PatchModes.AUTOMATIC_BY_PLATFORM
argument_composer.assessment_mode = "LetsThrowAnException"
runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.APT)
runtime.package_manager.get_current_auto_os_patch_state = runtime.backup_get_current_auto_os_patch_state
runtime.set_legacy_test_type('HappyPath')

# Execute main
CoreMain(argument_composer.get_composed_arguments())

# check telemetry events
self.__check_telemetry_events(runtime)

# check status file
with runtime.env_layer.file_system.open(runtime.execution_config.status_file_path, 'r') as file_handle:
substatus_file_data = json.load(file_handle)[0]["status"]["substatus"]
self.assertEqual(len(substatus_file_data), 2)
self.assertTrue(substatus_file_data[0]["name"] == Constants.PATCH_ASSESSMENT_SUMMARY) # assessment is now part of the CP flow
self.assertTrue(substatus_file_data[0]["status"].lower() == Constants.STATUS_SUCCESS.lower())
self.assertTrue(substatus_file_data[1]["name"] == Constants.CONFIGURE_PATCHING_SUMMARY)
self.assertTrue(substatus_file_data[1]["status"].lower() == Constants.STATUS_ERROR.lower())
message = json.loads(substatus_file_data[1]["formattedMessage"]["message"])
self.assertEqual(message["automaticOSPatchState"], Constants.AutomaticOSPatchStates.DISABLED)

Check warning on line 335 in src/core/tests/Test_ConfigurePatchingProcessor.py

View check run for this annotation

Codecov / codecov/patch

src/core/tests/Test_ConfigurePatchingProcessor.py#L334-L335

Added lines #L334 - L335 were not covered by tests

runtime.stop()

Check warning on line 337 in src/core/tests/Test_ConfigurePatchingProcessor.py

View check run for this annotation

Codecov / codecov/patch

src/core/tests/Test_ConfigurePatchingProcessor.py#L337

Added line #L337 was not covered by tests

def __check_telemetry_events(self, runtime):
all_events = os.listdir(runtime.telemetry_writer.events_folder_path)
self.assertTrue(len(all_events) > 0)
Expand Down

0 comments on commit 8f6b743

Please sign in to comment.