APT: Patch Mode set to disabled in ConfigurePatching when os patch config file does not exist (#216)
* APT: Patch Mode set to disabled in ConfigurePatching when os patch config file does not exist * APT: Patch Mode set to disabled in ConfigurePatching: Fixing failing unit tests * APT: Patch Mode set to disabled in ConfigurePatching: Trying a fix for codecov failure * APT: Patch Mode set to disabled in ConfigurePatching: resolving duplicate UT names
This commit is contained in:
Родитель
3d68c37e72
Коммит
bd81687be9
|
@ -476,8 +476,9 @@ class AptitudePackageManager(PackageManager):
|
|||
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
|
||||
|
|
|
@ -214,6 +214,15 @@ class TestAptitudePackageManager(unittest.TestCase):
|
|||
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')
|
||||
|
|
|
@ -35,7 +35,16 @@ class TestConfigurePatchingProcessor(unittest.TestCase):
|
|||
# self.runtime.stop()
|
||||
pass
|
||||
|
||||
def test_operation_success_for_configure_patching_request_for_apt(self):
|
||||
#region Mocks
|
||||
def mock_package_manager_get_current_auto_os_patch_state_returns_unknown(self):
|
||||
if self.mock_package_manager_get_current_auto_os_patch_state_returns_unknown_call_count == 0:
|
||||
self.mock_package_manager_get_current_auto_os_patch_state_returns_unknown_call_count = 1
|
||||
return Constants.AutomaticOSPatchStates.DISABLED
|
||||
else:
|
||||
return Constants.AutomaticOSPatchStates.UNKNOWN
|
||||
#endregion Mocks
|
||||
|
||||
def test_operation_success_for_configure_patching_request_for_apt_with_default_updates_config(self):
|
||||
# create and adjust arguments
|
||||
argument_composer = ArgumentComposer()
|
||||
argument_composer.operation = Constants.CONFIGURE_PATCHING
|
||||
|
@ -80,14 +89,28 @@ class TestConfigurePatchingProcessor(unittest.TestCase):
|
|||
# stop test runtime
|
||||
runtime.stop()
|
||||
|
||||
#region Mocks
|
||||
def mock_package_manager_get_current_auto_os_patch_state_returns_unknown(self):
|
||||
if self.mock_package_manager_get_current_auto_os_patch_state_returns_unknown_call_count == 0:
|
||||
self.mock_package_manager_get_current_auto_os_patch_state_returns_unknown_call_count = 1
|
||||
return Constants.AutomaticOSPatchStates.DISABLED
|
||||
else:
|
||||
return Constants.AutomaticOSPatchStates.UNKNOWN
|
||||
#endregion Mocks
|
||||
def test_operation_success_for_configure_patching_request_for_apt_without_default_updates_config(self):
|
||||
# default auto OS updates config file not found on the machine
|
||||
argument_composer = ArgumentComposer()
|
||||
argument_composer.operation = Constants.CONFIGURE_PATCHING
|
||||
argument_composer.patch_mode = Constants.PatchModes.AUTOMATIC_BY_PLATFORM
|
||||
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')
|
||||
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_SUCCESS.lower())
|
||||
runtime.stop()
|
||||
|
||||
def test_operation_success_for_installation_request_with_configure_patching(self):
|
||||
argument_composer = ArgumentComposer()
|
||||
|
@ -163,29 +186,6 @@ class TestConfigurePatchingProcessor(unittest.TestCase):
|
|||
self.assertTrue(substatus_file_data[0]["status"].lower() == Constants.STATUS_SUCCESS.lower())
|
||||
runtime.stop()
|
||||
|
||||
def test_operation_fail_for_configure_patching_request_for_apt(self):
|
||||
# default auto OS updates config file not found on the machine
|
||||
argument_composer = ArgumentComposer()
|
||||
argument_composer.operation = Constants.CONFIGURE_PATCHING
|
||||
argument_composer.patch_mode = Constants.PatchModes.AUTOMATIC_BY_PLATFORM
|
||||
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')
|
||||
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())
|
||||
runtime.stop()
|
||||
|
||||
def test_patch_mode_set_failure_for_configure_patching(self):
|
||||
argument_composer = ArgumentComposer()
|
||||
argument_composer.operation = Constants.CONFIGURE_PATCHING
|
||||
|
|
Загрузка…
Ссылка в новой задаче