diff --git a/src/core/src/package_managers/YumPackageManager.py b/src/core/src/package_managers/YumPackageManager.py index dc888dd8..f24107aa 100644 --- a/src/core/src/package_managers/YumPackageManager.py +++ b/src/core/src/package_managers/YumPackageManager.py @@ -260,7 +260,6 @@ def install_updates_fail_safe(self, excluded_packages): for excluded_package in excluded_packages: excluded_string += excluded_package + ' ' cmd = self.all_but_excluded_upgrade_cmd + excluded_string - self.composite_logger.log_debug("[YPM][FAIL SAFE MODE] UPDATING PACKAGES USING COMMAND: " + cmd) self.invoke_package_manager(cmd) diff --git a/src/core/tests/Test_YumPackageManager.py b/src/core/tests/Test_YumPackageManager.py index 44d0027a..e0ccc167 100644 --- a/src/core/tests/Test_YumPackageManager.py +++ b/src/core/tests/Test_YumPackageManager.py @@ -49,6 +49,18 @@ def mock_linux7_distribution_to_return_redhat(self): def mock_linux8_distribution_to_return_redhat(self): return ['Red Hat Enterprise Linux Server', '8', 'Ootpa'] + + def mock_centos_linux_distribution(self): + return ['CentOS Linux', '7.9.2009', 'Core'] + + def mock_get_all_updates(self, cached): + return [], [] + + def mock_get_security_updates(self): + return [], [] + + def mock_bad_run_command_output(self, cmd, no_output=False, chk_err=False): + return 1, "bad cmd" #endregion Mocks # region Utility Functions @@ -1253,6 +1265,69 @@ def test_get_dependent_list_yum_version_4_update_in_two_lines_with_unexpected_ou dependent_list = package_manager.get_dependent_list(["polkit.x86_64"]) self.assertEqual(len(dependent_list), 0) + def test_get_other_updates_exception(self): + """ test get_other_updates throw exception path. """ + # Set up + package_manager = self.runtime.container.get('package_manager') + package_manager.get_all_updates = self.mock_get_all_updates + package_manager.get_security_updates = self.mock_get_security_updates + self.runtime.env_layer.platform.linux_distribution = self.mock_centos_linux_distribution + + # Act + with self.assertRaises(Exception) as context: + package_manager.get_other_updates() + + # Assert + print(str(context.exception)) + self.assertTrue("Classification-based patching is only supported on YUM if the computer is independently configured to receive classification information." in str(context.exception)) + + def test_install_updates_fail_safe(self): + """Test install_updates_fail_safe """ + # Set up + test_excluded_pkgs = ["kernel.x86_64", "kernel.i686", "tzdata.noarch"] + package_manager = self.container.get('package_manager') + self.assertIsNotNone(package_manager) + + # Act + result = package_manager.install_updates_fail_safe(test_excluded_pkgs) + + # Verify + self.assertIsNone(result) + + self.runtime.stop() + + def test_get_product_arch(self): + """ Test get_product_arch method to return pkg arch type.""" + # Set up + test_pkg_name = "selinux-policy.noarch" + package_manager = self.container.get('package_manager') + self.assertIsNotNone(package_manager) + + # Act + result = package_manager.get_product_arch(test_pkg_name) + + # verify + self.assertEqual(".noarch", result) + + self.runtime.stop() + + def test_disable_auto_update_on_reboot_exception(self): + """ test disable_auto_update_on_reboot throw exception path. """ + # Set up + bad_disable_cmd = "systemctl disable yum-cron123" + package_manager = self.runtime.container.get('package_manager') + package_manager.env_layer.run_command_output = self.mock_bad_run_command_output + + # Act + with self.assertRaises(Exception) as context: + package_manager.disable_auto_update_on_reboot(bad_disable_cmd) + + # Assert + print(str(context.exception)) + self.assertTrue("Unexpected return code (1) on command: systemctl disable yum-cron123" in str(context.exception)) + + if __name__ == '__main__': unittest.main() +