def get_stack_version_before_packages_installed(self): """ This works in a lazy way (calculates the version first time and stores it). If you need to recalculate the version explicitly set: Script.stack_version_from_distro_select = None before the call. However takes a bit of time, so better to avoid. :return: stack version including the build number. e.g.: 2.3.4.0-1234. """ from resource_management.libraries.functions import stack_select from ambari_commons.repo_manager import ManagerFactory # preferred way is to get the actual selected version of current component stack_select_package_name = stack_select.get_package_name() if not Script.stack_version_from_distro_select and stack_select_package_name: Script.stack_version_from_distro_select = stack_select.get_stack_version_before_install(stack_select_package_name) # If <stack-selector-tool> has not yet been done (situations like first install), # we can use <stack-selector-tool> version itself. # Wildcards cause a lot of troubles with installing packages, if the version contains wildcards we should try to specify it. if not Script.stack_version_from_distro_select or '*' in Script.stack_version_from_distro_select: # FIXME: this method is not reliable to get stack-selector-version # as if there are multiple versions installed with different <stack-selector-tool>, we won't detect the older one (if needed). pkg_provider = ManagerFactory.get() Script.stack_version_from_distro_select = pkg_provider.get_installed_package_version( stack_tools.get_stack_tool_package(stack_tools.STACK_SELECTOR_NAME)) return Script.stack_version_from_distro_select
def load_available_packages(self): from ambari_commons.repo_manager import ManagerFactory if self.available_packages_in_repos: return self.available_packages_in_repos config = self.get_config() service_name = config['serviceName'] if 'serviceName' in config else None repos = CommandRepository(config['repositoryFile']) repo_ids = [repo.repo_id for repo in repos.items] Logger.info("Command repositories: {0}".format(", ".join(repo_ids))) repos.items = [x for x in repos.items if (not x.applicable_services or service_name in x.applicable_services) ] applicable_repo_ids = [repo.repo_id for repo in repos.items] Logger.info("Applicable repositories: {0}".format(", ".join(applicable_repo_ids))) pkg_provider = ManagerFactory.get() try: self.available_packages_in_repos = pkg_provider.get_available_packages_in_repos(repos) except Exception as err: Logger.exception("Unable to load available packages") self.available_packages_in_repos = [] return self.available_packages_in_repos
def upgrade_logsearch_portal(self, env): pkg_provider = ManagerFactory.get() context = RepoCallContext() context.log_output = True pkg_provider.remove_package( 'ambari-logsearch-portal', context, ignore_dependencies=True) pkg_provider.upgrade_package('ambari-logsearch-portal', context)
def load_available_packages(self): from ambari_commons.repo_manager import ManagerFactory if self.available_packages_in_repos: return self.available_packages_in_repos config = self.get_config() service_name = config['serviceName'] if 'serviceName' in config else None repos = CommandRepository(config['repositoryFile']) from resource_management.libraries.functions import lzo_utils # remove repos with 'GPL' tag when GPL license is not approved repo_tags_to_skip = set() if not lzo_utils.is_gpl_license_accepted(): repo_tags_to_skip.add("GPL") repos.items = [r for r in repos.items if not (repo_tags_to_skip & r.tags)] repo_ids = [repo.repo_id for repo in repos.items] Logger.info("Command repositories: {0}".format(", ".join(repo_ids))) repos.items = [x for x in repos.items if (not x.applicable_services or service_name in x.applicable_services) ] applicable_repo_ids = [repo.repo_id for repo in repos.items] Logger.info("Applicable repositories: {0}".format(", ".join(applicable_repo_ids))) pkg_provider = ManagerFactory.get() try: self.available_packages_in_repos = pkg_provider.get_available_packages_in_repos(repos) except Exception as err: Logger.exception("Unable to load available packages") self.available_packages_in_repos = [] return self.available_packages_in_repos
def upgrade_solr_instance(self, env): pkg_provider = ManagerFactory.get() context = RepoCallContext() context.log_output = True pkg_provider.remove_package('ambari-infra-solr', context, ignore_dependencies=True) pkg_provider.upgrade_package('ambari-infra-solr', context)
def upgrade_solr_client(self, env): pkg_provider = ManagerFactory.get() context = RepoCallContext() context.is_upgrade=True context.log_output = True context.use_repos = {} context.use_repos['ambari']=get_ambari_repo_file_full_name() pkg_provider.remove_package('ambari-infra-solr-client', context, ignore_dependencies=True) pkg_provider.upgrade_package('ambari-infra-solr-client', context)
def test_install_hbase_master_with_version(self, get_provider): from ambari_commons.os_check import OSConst from ambari_commons.repo_manager import ManagerFactory pkg_manager = ManagerFactory.get_new_instance(OSConst.REDHAT_FAMILY) with patch.object(pkg_manager, "all_packages") as all_packages,\ patch.object(pkg_manager, "available_packages") as available_packages, \ patch.object(pkg_manager, "installed_packages") as installed_packages: all_packages.return_value = [["hbase_2_3_0_1_1234", "1.0", "testrepo"]] available_packages.return_value = [["hbase_2_3_0_1_1234", "1.0", "testrepo"]] installed_packages.return_value = [["hbase_2_3_0_1_1234", "1.0", "testrepo"]] get_provider.return_value = pkg_manager config_file = self.get_src_folder()+"/test/python/stacks/2.0.6/configs/hbase_with_phx.json" with open(config_file, "r") as f: json_content = json.load(f) version = '2.3.0.1-1234' # the json file is not a "well formed" install command json_content['roleCommand'] = 'INSTALL' json_content['commandParams']['version'] = version json_content['commandParams']['package_list'] = "[{\"name\":\"hbase_${stack_version}\",\"condition\":\"\",\"skipUpgrade\":false}]" self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hbase_master.py", classname = "HbaseMaster", command = "install", config_dict = json_content, stack_version = self.STACK_VERSION, target = RMFTestCase.TARGET_COMMON_SERVICES, try_install=True, os_type=('Redhat', '6.4', 'Final'), checked_call_mocks = [(0, "OK.", "")], available_packages_in_repos = ['hbase_2_3_0_1_1234'], ) # only assert that the correct package is trying to be installed self.assertResourceCalled('Package', 'hbase_2_3_0_1_1234', retry_count=5, retry_on_repo_unavailability=False) def test_configure_default(self): self.executeScript(self.COMMON_SERVICES_PACKAGE_DIR + "/scripts/hbase_master.py", classname = "HbaseMaster", command = "configure", config_file="default.json", stack_version = self.STACK_VERSION, target = RMFTestCase.TARGET_COMMON_SERVICES ) self.assert_configure_default() self.assertNoMoreResources()
def upgrade_logsearch_portal(self, env): pkg_provider = ManagerFactory.get() context = RepoCallContext() context.is_upgrade = True context.log_output = True context.use_repos = {} context.use_repos['ambari'] = get_ambari_repo_file_full_name() pkg_provider.remove_package('ambari-logsearch-portal', context, ignore_dependencies=True) pkg_provider.upgrade_package('ambari-logsearch-portal', context)
def actionexecute(self, env): config = Script.get_config() structured_output = {} version = config['commandParams']['version'] self.stack_tool_package = stack_tools.get_stack_tool_package( stack_tools.STACK_SELECTOR_NAME) versions_to_remove = self.get_lower_versions(version) self.pkg_provider = ManagerFactory.get() for low_version in versions_to_remove: self.remove_stack_version(structured_output, low_version)
def __init__(self): super(InstallPackages, self).__init__() self.repo_mgr = ManagerFactory.get() self.repo_files = {}
def __init__(self): self.reportFileHandler = HostCheckReportFileHandler() self.pkg_provider = ManagerFactory.get()
def __init__(self, *args, **kwargs): super(PackageProvider, self).__init__(*args, **kwargs) self._pkg_manager = ManagerFactory.get()
class TestPackageResource(TestCase): @patch.object(ac_shell, "process_executor") @patch.object(ManagerFactory, "get", new=MagicMock(return_value=ManagerFactory.get_new_instance( OSConst.REDHAT_FAMILY))) def test_action_install_pattern_rhel(self, shell_mock): shell_mock.return_value.__enter__.return_value = [] sys.modules['rpm'] = MagicMock() sys.modules['rpm'].TransactionSet.return_value = MagicMock() sys.modules['rpm'].TransactionSet.return_value.dbMatch.return_value = [ { 'name': 'some_packag' } ] with Environment('/') as env: Package("some_package*", logoutput=False) self.assertEquals(shell_mock.call_args_list[0][0][0], [ '/usr/bin/yum', '-d', '0', '-e', '0', '-y', 'install', 'some_package*' ]) @patch.object(ac_shell, "process_executor") @patch.object(ManagerFactory, "get", new=MagicMock(return_value=ManagerFactory.get_new_instance( OSConst.REDHAT_FAMILY))) def test_action_install_pattern_installed_rhel(self, shell_mock): shell_mock.return_value = (0, '') sys.modules['yum'] = MagicMock() sys.modules['yum'].YumBase.return_value = MagicMock() sys.modules['yum'].YumBase.return_value.rpmdb = MagicMock() sys.modules[ 'yum'].YumBase.return_value.rpmdb.simplePkgList.return_value = [ ('some_package_1_2_3', ) ] with Environment('/') as env: Package("some_package*", logoutput=False) self.assertEqual(shell_mock.call_count, 0, "shell.checked_call shouldn't be called") @patch.object(ac_shell, "process_executor") @patch.object( ManagerFactory, "get", new=MagicMock( return_value=ManagerFactory.get_new_instance(OSConst.SUSE_FAMILY))) def test_action_install_pattern_suse(self, shell_mock, call_mock): call_mock.side_effect = [ (0, None), (0, "Loading repository data...\nReading installed packages...\n\nS | Name\n--+-----\n | Pack" ) ] with Environment('/') as env: Package("some_package*", ) call_mock.assert_has_calls([ call( "installed_pkgs=`rpm -qa 'some_package*'` ; [ ! -z \"$installed_pkgs\" ]" ), call( "zypper --non-interactive search --type package --uninstalled-only --match-exact 'some_package*'" ) ]) self.assertEquals(shell_mock.call_args_list[0][0][0], [ '/usr/bin/zypper', '--quiet', 'install', '--auto-agree-with-licenses', '--no-confirm', 'some_package*' ]) @patch.object(ac_shell, "process_executor") @patch.object( ManagerFactory, "get", new=MagicMock( return_value=ManagerFactory.get_new_instance(OSConst.SUSE_FAMILY))) def test_action_install_pattern_suse(self, shell_mock): sys.modules['rpm'] = MagicMock() sys.modules['rpm'].TransactionSet.return_value = MagicMock() sys.modules['rpm'].TransactionSet.return_value.dbMatch.return_value = [ { 'name': 'some_packagetest' } ] with Environment('/') as env: Package("some_package*", ) self.assertEqual(shell_mock.call_count, 0, "shell.checked_call shouldn't be called") @patch.object(ac_shell, "process_executor") @patch.object(ManagerFactory, "get", new=MagicMock(return_value=ManagerFactory.get_new_instance( OSConst.REDHAT_FAMILY))) def test_action_install_existent_rhel(self, shell_mock): sys.modules['rpm'] = MagicMock() sys.modules['rpm'].TransactionSet.return_value = MagicMock() sys.modules['rpm'].TransactionSet.return_value.dbMatch.return_value = [ { 'name': 'some_package' } ] with Environment('/') as env: Package("some_package", ) self.assertFalse(shell_mock.call_count > 0) @patch.object(ac_shell, "process_executor") @patch.object( ManagerFactory, "get", new=MagicMock( return_value=ManagerFactory.get_new_instance(OSConst.SUSE_FAMILY))) def test_action_install_existent_suse(self, shell_mock): sys.modules['rpm'] = MagicMock() sys.modules['rpm'].TransactionSet.return_value = MagicMock() sys.modules['rpm'].TransactionSet.return_value.dbMatch.return_value = [ { 'name': 'some_package' } ] with Environment('/') as env: Package("some_package", ) self.assertFalse(shell_mock.call_count > 0) @patch.object(ac_shell, "process_executor") @patch.object(ManagerFactory, "get", new=MagicMock(return_value=ManagerFactory.get_new_instance( OSConst.REDHAT_FAMILY))) def test_action_remove_rhel(self, shell_mock): sys.modules['rpm'] = MagicMock() sys.modules['rpm'].TransactionSet.return_value = MagicMock() sys.modules['rpm'].TransactionSet.return_value.dbMatch.return_value = [ { 'name': 'some_package' } ] with Environment('/') as env: Package("some_package", action="remove", logoutput=False) self.assertEquals(shell_mock.call_args_list[0][0][0], [ '/usr/bin/yum', '-d', '0', '-e', '0', '-y', 'erase', 'some_package' ]) @replace_underscores def func_to_test(self, name): return name def testReplaceUnderscore(self): self.assertEqual("-", self.func_to_test("_")) self.assertEqual("hadoop-x-x-x-*", self.func_to_test("hadoop_x_x_x-*")) self.assertEqual("hadoop", self.func_to_test("hadoop"))