def test_vefify_dependency_suse(self, logger_mock, in_family_patch_mock, checked_call_mock): test_cases = [{ "name": "SUSE Case", "os": OSConst.SUSE_FAMILY, "cheked_call_result": "5 new packages to install" }, { "name": "REDHAT Case", "os": OSConst.REDHAT_FAMILY, "cheked_call_result": "Error:" }, { "name": "UBUNTU Case", "os": OSConst.UBUNTU_FAMILY, "cheked_call_result": "E:" }] for test_case in test_cases: in_family_patch_mock.side_effect = lambda current_family, family: family == test_case[ "os"] checked_call_mock.return_value = (0, "OK.") # happy scenario self.assertTrue( packages_analyzer.verifyDependencies(), "test_verify_dependency failed on '%s'" % test_case["name"]) # unhappy scenario checked_call_mock.return_value = (0, test_case["cheked_call_result"]) self.assertFalse( packages_analyzer.verifyDependencies(), "test_verify_dependency failed on '%s'" % test_case["name"]) # try: in_family_patch_mock.side_effect = lambda current_family, family: False packages_analyzer.verifyDependencies() self.assertTrue(False, "Wrong handling of unknown operation system") except Fail: pass
def test_vefify_dependency_suse(self, logger_mock, in_family_patch_mock, checked_call_mock): test_cases = [ { "name": "SUSE Case", "os": OSConst.SUSE_FAMILY, "cheked_call_result": "5 new packages to install" }, { "name": "REDHAT Case", "os": OSConst.REDHAT_FAMILY, "cheked_call_result": "Error:" }, { "name": "UBUNTU Case", "os": OSConst.UBUNTU_FAMILY, "cheked_call_result": "E:" } ] for test_case in test_cases: in_family_patch_mock.side_effect = lambda current_family, family: family == test_case["os"] checked_call_mock.return_value = (0, "OK.") # happy scenario self.assertTrue(packages_analyzer.verifyDependencies(), "test_verify_dependency failed on '%s'" % test_case["name"]) # unhappy scenario checked_call_mock.return_value = (0, test_case["cheked_call_result"]) self.assertFalse(packages_analyzer.verifyDependencies(), "test_verify_dependency failed on '%s'" % test_case["name"]) # try: in_family_patch_mock.side_effect = lambda current_family, family: False packages_analyzer.verifyDependencies() self.assertTrue(False, "Wrong handling of unknown operation system") except Fail: pass
def install_packages(self, package_list): """ Actually install the packages using the package manager. :param package_list: List of package names to install :return: Returns 0 if no errors were found, and 1 otherwise. """ ret_code = 0 config = self.get_config() agent_stack_retry_on_unavailability = cbool( config['hostLevelParams']['agent_stack_retry_on_unavailability']) agent_stack_retry_count = cint( config['hostLevelParams']['agent_stack_retry_count']) # Install packages packages_were_checked = False stack_selector_package = stack_tools.get_stack_tool_package( stack_tools.STACK_SELECTOR_NAME) try: Package(stack_selector_package, action="upgrade", retry_on_repo_unavailability= agent_stack_retry_on_unavailability, retry_count=agent_stack_retry_count) packages_installed_before = [] allInstalledPackages(packages_installed_before) packages_installed_before = [ package[0] for package in packages_installed_before ] packages_were_checked = True filtered_package_list = self.filter_package_list(package_list) try: available_packages_in_repos = packages_analyzer.get_available_packages_in_repos( config['repositoryFile']['repositories']) except Exception: available_packages_in_repos = [] for package in filtered_package_list: name = self.get_package_from_available( package['name'], available_packages_in_repos) Package( name, action= "upgrade", # this enables upgrading non-versioned packages, despite the fact they exist. Needed by 'mahout' which is non-version but have to be updated retry_on_repo_unavailability= agent_stack_retry_on_unavailability, retry_count=agent_stack_retry_count) except Exception as err: ret_code = 1 Logger.logger.exception( "Package Manager failed to install packages. Error: {0}". format(str(err))) # Remove already installed packages in case of fail if packages_were_checked and packages_installed_before: packages_installed_after = [] allInstalledPackages(packages_installed_after) packages_installed_after = [ package[0] for package in packages_installed_after ] packages_installed_before = set(packages_installed_before) new_packages_installed = [ package for package in packages_installed_after if package not in packages_installed_before ] if OSCheck.is_ubuntu_family(): package_version_string = self.repository_version.replace( '.', '-') else: package_version_string = self.repository_version.replace( '-', '_') package_version_string = package_version_string.replace( '.', '_') for package in new_packages_installed: if package_version_string and (package_version_string in package): Package(package, action="remove") if not verifyDependencies(): ret_code = 1 Logger.logger.error("Failure while verifying dependencies") Logger.logger.error( "*******************************************************************************" ) Logger.logger.error( "Manually verify and fix package dependencies and then re-run install_packages" ) Logger.logger.error( "*******************************************************************************" ) # Compute the actual version in order to save it in structured out try: if ret_code == 0: self.compute_actual_version() else: self.check_partial_install() except Fail as err: ret_code = 1 Logger.logger.exception( "Failure while computing actual version. Error: {0}".format( str(err))) return ret_code