From b4e5242688e9460f21b0b826025c4b34493fbbdc Mon Sep 17 00:00:00 2001 From: Koshy John Date: Tue, 31 Oct 2023 10:42:37 -0700 Subject: [PATCH] Increased test coverage --- src/core/tests/Test_CoreMain.py | 2 ++ src/core/tests/Test_PatchInstaller.py | 20 +++++++++++++++++-- .../tests/library/LegacyEnvLayerExtensions.py | 11 ++++------ src/core/tests/library/RuntimeCompositor.py | 2 ++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/core/tests/Test_CoreMain.py b/src/core/tests/Test_CoreMain.py index ee0689d5..87e22c6f 100644 --- a/src/core/tests/Test_CoreMain.py +++ b/src/core/tests/Test_CoreMain.py @@ -132,6 +132,8 @@ def test_operation_success_for_autopatching_request(self): argument_composer.maintenance_run_id = str(maintenance_run_id) argument_composer.health_store_id = str("2020.09.28") runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.ZYPPER) + Constants.MAX_FILE_OPERATION_RETRY_COUNT = 2 # to retain retry coverage in at least one test + Constants.MAX_IMDS_CONNECTION_RETRY_COUNT = 2 # to retain retry coverage in at least one test runtime.set_legacy_test_type('SuccessInstallPath') CoreMain(argument_composer.get_composed_arguments()) diff --git a/src/core/tests/Test_PatchInstaller.py b/src/core/tests/Test_PatchInstaller.py index f8a192ef..baf14e47 100644 --- a/src/core/tests/Test_PatchInstaller.py +++ b/src/core/tests/Test_PatchInstaller.py @@ -239,14 +239,30 @@ def test_patch_installer_for_azgps_coordinated(self): # Path change runtime.set_legacy_test_type('HappyPath') self.assertTrue(runtime.patch_installer.start_installation()) - self.assertEqual(runtime.execution_config.max_patch_publish_date,"20240401T000000Z") + self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z") + self.assertEqual(runtime.package_manager.max_patch_publish_date,"20240401T000000Z") # supported and conditions met runtime.stop() argument_composer.maximum_duration = "PT30M" runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.APT) runtime.set_legacy_test_type('HappyPath') - self.assertFalse(runtime.patch_installer.start_installation()) + self.assertFalse(runtime.patch_installer.start_installation()) # failure is in unrelated patch installation batch processing + self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z") + self.assertEqual(runtime.package_manager.max_patch_publish_date, "") # reason: not enough time to use + runtime.stop() + + runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.YUM) + runtime.set_legacy_test_type('HappyPath') + self.assertTrue(runtime.patch_installer.start_installation()) + self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z") + self.assertEqual(runtime.package_manager.max_patch_publish_date, "") # unsupported in Yum + runtime.stop() + + runtime = RuntimeCompositor(argument_composer.get_composed_arguments(), True, Constants.ZYPPER) + runtime.set_legacy_test_type('HappyPath') + self.assertFalse(runtime.patch_installer.start_installation()) # failure is in unrelated patch installation batch processing self.assertEqual(runtime.execution_config.max_patch_publish_date, "20240401T000000Z") + self.assertEqual(runtime.package_manager.max_patch_publish_date, "") # unsupported in Zypper runtime.stop() def test_mark_status_completed_esm_required(self): diff --git a/src/core/tests/library/LegacyEnvLayerExtensions.py b/src/core/tests/library/LegacyEnvLayerExtensions.py index d2e040f3..a3d34bfc 100644 --- a/src/core/tests/library/LegacyEnvLayerExtensions.py +++ b/src/core/tests/library/LegacyEnvLayerExtensions.py @@ -462,9 +462,10 @@ def run_command_output(self, cmd, no_output=False, chk_err=True): "Ubuntu:16.10/yakkety-updates, Ubuntu:16.10/yakkety-security [amd64]) []\n" elif cmd.find("grep -hR security /etc/apt/sources.list") > -1 or cmd.find("grep -hR \"\" /etc/apt/sources.list") > -1: code = 0 - output = "deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security main restricted\n" + \ - "deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security universe\n" + \ - "deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security multiverse" + output = ("deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security main restricted\n" + "deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security universe\n" + "deb-src http://azure.archive.ubuntu.com/ubuntu/ jammy-security multiverse\n" + "deb-src https://snapshot.ubuntu.com/ubuntu/20240301T000000Z jammy-security universe") self.write_to_file(os.path.join(self.temp_folder_path, "temp2.list"), output) elif cmd.find("--only-upgrade true -s install") > -1 or cmd.find("apt-get -y --only-upgrade true upgrade") > -1: code = 0 @@ -532,10 +533,6 @@ def run_command_output(self, cmd, no_output=False, chk_err=True): output = " bash | 4.3-14ubuntu1.3 | http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages\n" + \ " bash | 4.3-14ubuntu1.2 | http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages\n" + \ " bash | 4.3-14ubuntu1 | http://us.archive.ubuntu.com/ubuntu xenial/main amd64 Packages" - elif cmd.find('sudo grep -hR security /etc/apt/sources.list /etc/apt/sources.list.d/ >') > -1: - self.write_to_file(os.path.join(self.temp_folder_path, "temp2.list"), "test temp file 2") - code = 0 - output = "tmp file created" elif cmd.find('sudo apt-get install ubuntu-advantage-tools -y') > -1: code = 0 elif cmd.find('pro security-status --format=json') > -1: diff --git a/src/core/tests/library/RuntimeCompositor.py b/src/core/tests/library/RuntimeCompositor.py index 98f5d9a5..d8f3e623 100644 --- a/src/core/tests/library/RuntimeCompositor.py +++ b/src/core/tests/library/RuntimeCompositor.py @@ -146,6 +146,8 @@ def reconfigure_env_layer_to_legacy_mode(self): self.env_layer.platform = self.legacy_env_layer_extensions.LegacyPlatform() self.env_layer.set_legacy_test_mode() self.env_layer.run_command_output = self.legacy_env_layer_extensions.run_command_output + if os.name == 'nt': + self.env_layer.etc_environment_file_path = os.getcwd() def reconfigure_reboot_manager(self): self.reboot_manager.start_reboot = self.start_reboot