def test_is_suse_family(self, get_os_family_mock): get_os_family_mock.return_value = "suse" self.assertEqual(OSCheck.is_suse_family(), True) get_os_family_mock.return_value = "troll_os" self.assertEqual(OSCheck.is_suse_family(), False)
def get_ntp_service(): if OSCheck.is_redhat_family() and int(OSCheck.get_os_major_version()) >= 7: return ("chronyd", "ntpd",) elif OSCheck.is_redhat_family(): return ("ntpd",) elif OSCheck.is_suse_family() or OSCheck.is_ubuntu_family(): return ("ntp",)
def installAgent(projectVersion, ret=None): """ Run install and make sure the agent install alright """ # The command doesn't work with file mask ambari-agent*.rpm, so rename it on agent host if OSCheck.is_suse_family(): Command = [ "zypper", "--no-gpg-checks", "install", "-y", "ambari-agent-" + projectVersion ] elif OSCheck.is_ubuntu_family(): # add * to end of version in case of some test releases Command = [ "apt-get", "install", "-y", "--allow-unauthenticated", "ambari-agent=" + projectVersion + "*" ] elif OSCheck.is_windows_family(): packageParams = "/AmbariRoot:" + AMBARI_INSTALL_ROOT Command = [ "cmd", "/c", "choco", "install", "-y", "ambari-agent", "--version=" + projectVersion, "--params=\"" + packageParams + "\"" ] else: Command = [ "yum", "-y", "install", "--nogpgcheck", "ambari-agent-" + projectVersion ] return execOsCommand(Command, tries=3, try_sleep=10, ret=ret)
def find_repo_files_for_repos(self, repoNames): repoFiles = [] osType = OSCheck.get_os_family() repoNameList = [] for repoName in repoNames: if len(repoName.strip()) > 0: repoNameList.append("[" + repoName + "]") repoNameList.append("name=" + repoName) if repoNameList: # get list of files if OSCheck.is_suse_family(): fileList = self.get_files_in_dir(REPO_PATH_SUSE) elif OSCheck.is_redhat_family(): fileList = self.get_files_in_dir(REPO_PATH_RHEL) elif OSCheck.is_ubuntu_family(): fileList = self.get_files_in_dir(REPO_PATH_UBUNTU) else: logger.warn( "Unsupported OS type, cannot get repository location.") return [] if fileList: for filePath in fileList: with open(filePath, 'r') as file: content = file.readline() while (content != ""): for repoName in repoNameList: if content.find( repoName ) == 0 and filePath not in repoFiles: repoFiles.append(filePath) break content = file.readline() return repoFiles
def findNearestAgentPackageVersion(projectVersion): if projectVersion == "": projectVersion = " " if OSCheck.is_suse_family(): Command = [ "bash", "-c", "zypper -q search -s --match-exact ambari-agent | grep '" + projectVersion + "' | cut -d '|' -f 4 | head -n1 | sed -e 's/-\w[^:]*//1' " ] elif OSCheck.is_debian_family(): if projectVersion == " ": Command = [ "bash", "-c", "apt-cache -q show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|tr -d '\\n'|sed -s 's/[-|~][A-Za-z0-9]*//'" ] else: Command = [ "bash", "-c", "apt-cache -q show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|grep '" + projectVersion + "'|tr -d '\\n'|sed -s 's/[-|~][A-Za-z\d]*//'" ] else: Command = [ "bash", "-c", "yum -q list all ambari-agent | grep '" + projectVersion + "' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | head -n1 | sed -e 's/-\w[^:]*//1' " ] return execOsCommand(Command)
def find_repo_files_for_repos(self, repoNames): repoFiles = [] osType = OSCheck.get_os_family() repoNameList = [] for repoName in repoNames: if len(repoName.strip()) > 0: repoNameList.append("[" + repoName + "]") repoNameList.append("name=" + repoName) if repoNameList: # get list of files if OSCheck.is_suse_family(): fileList = self.get_files_in_dir(REPO_PATH_SUSE) elif OSCheck.is_redhat_family(): fileList = self.get_files_in_dir(REPO_PATH_RHEL) elif OSCheck.is_ubuntu_family(): fileList = self.get_files_in_dir(REPO_PATH_UBUNTU) else: logger.warn("Unsupported OS type, cannot get repository location.") return [] if fileList: for filePath in fileList: with open(filePath, 'r') as file: content = file.readline() while (content != "" ): for repoName in repoNameList: if content.find(repoName) == 0 and filePath not in repoFiles: repoFiles.append(filePath) break; content = file.readline() return repoFiles
def action_create(self): with Environment.get_instance_copy() as env: repo_file_name = self.resource.repo_file_name repo_dir = get_repo_dir() new_content = InlineTemplate( self.resource.repo_template, repo_id=self.resource.repo_id, repo_file_name=self.resource.repo_file_name, base_url=self.resource.base_url, mirror_list=self.resource.mirror_list) repo_file_path = format("{repo_dir}/{repo_file_name}.repo") if os.path.isfile(repo_file_path): existing_content_str = sudo.read_file(repo_file_path) new_content_str = new_content.get_content() if existing_content_str != new_content_str and OSCheck.is_suse_family( ): # We need to reset package manager's cache when we replace base urls # at existing repo. That is a case at least under SLES Logger.info( "Flushing package manager cache since repo file content is about to change" ) checked_call(self.update_cmd, sudo=True) if self.resource.append_to_file: content = existing_content_str + '\n' + new_content_str else: content = new_content_str else: # If repo file does not exist yet content = new_content File(repo_file_path, content=content)
def verifyDependencies(): """ Verify that we have no dependency issues in package manager. Dependency issues could appear because of aborted or terminated package installation process or invalid packages state after manual modification of packages list on the host :return True if no dependency issues found, False if dependency issue present :rtype bool """ check_str = None cmd = None if OSCheck.is_redhat_family(): cmd = ['/usr/bin/yum', '-d', '0', '-e', '0', 'check', 'dependencies'] check_str = "has missing requires|Error:" elif OSCheck.is_suse_family(): cmd = ['/usr/bin/zypper', '--quiet', '--non-interactive' 'verify', '--dry-run'] check_str = "\d+ new package(s)? to install" elif OSCheck.is_ubuntu_family(): cmd = ['/usr/bin/apt-get', '-qq', 'check'] check_str = "has missing dependency|E:" if check_str is None or cmd is None: raise Fail("Unsupported OSFamily on the Agent Host") code, out = rmf_shell.checked_call(cmd, sudo=True) output_regex = re.compile(check_str) if code or (out and output_regex.search(out)): err_msg = Logger.filter_text("Failed to verify package dependencies. Execution of '%s' returned %s. %s" % (cmd, code, out)) Logger.error(err_msg) return False return True
def action_create(self): with Environment.get_instance_copy() as env: repo_file_name = self.resource.repo_file_name repo_dir = get_repo_dir() new_content = InlineTemplate(self.resource.repo_template, repo_id=self.resource.repo_id, repo_file_name=self.resource.repo_file_name, base_url=self.resource.base_url, mirror_list=self.resource.mirror_list) repo_file_path = format("{repo_dir}/{repo_file_name}.repo") if os.path.isfile(repo_file_path): existing_content_str = sudo.read_file(repo_file_path) new_content_str = new_content.get_content() if existing_content_str != new_content_str and OSCheck.is_suse_family(): # We need to reset package manager's cache when we replace base urls # at existing repo. That is a case at least under SLES Logger.info("Flushing package manager cache since repo file content is about to change") checked_call(self.update_cmd, sudo=True) if self.resource.append_to_file: content = existing_content_str + '\n' + new_content_str else: content = new_content_str else: # If repo file does not exist yet content = new_content File(repo_file_path, content=content )
def get_ntp_service(): if OSCheck.is_redhat_family(): return ("ntpd", "chronyd",) elif OSCheck.is_suse_family(): return ("ntpd", "ntp",) elif OSCheck.is_ubuntu_family(): return ("ntp", "chrony",)
def getFirewallObject(self): if OSCheck.is_ubuntu_family(): return UbuntuFirewallChecks() elif self.OS_TYPE == OSConst.OS_FEDORA and int(self.OS_VERSION) >= 18: return Fedora18FirewallChecks() elif OSCheck.is_suse_family(): return SuseFirewallChecks() else: return FirewallChecks()
def get_pg_hba_init_files(): if OSCheck.is_ubuntu_family(): return '/etc/postgresql' elif OSCheck.is_redhat_family(): return '/etc/rc.d/init.d/postgresql' elif OSCheck.is_suse_family(): return '/etc/init.d/postgresql' else: raise Exception("Unsupported OS family '{0}'".format(OSCheck.get_os_family()))
def get_erase_cmd(): if OSCheck.is_redhat_family(): return "yum erase -y {0}" elif OSCheck.is_suse_family(): return "zypper -n -q remove {0}" elif OSCheck.is_ubuntu_family(): return "/usr/bin/apt-get -y -q remove {0}" else: raise Exception("Unsupported OS family '{0}', cannot remove package. ".format(OSCheck.get_os_family()))
def getRepoDir(self): if OSCheck.is_redhat_family(): return "/etc/yum.repos.d" elif OSCheck.is_suse_family(): return "/etc/zypp/repos.d" elif OSCheck.is_ubuntu_family(): return "/etc/apt/sources.list.d" else: raise Exception("Unsupported OS family '{0}'".format(OSCheck.get_os_family()))
def get_pg_hba_init_files(): if OSCheck.is_ubuntu_family(): return '/etc/postgresql' elif OSCheck.is_redhat_family(): return '/etc/rc.d/init.d/postgresql' elif OSCheck.is_suse_family(): return '/etc/init.d/postgresql' else: raise Exception("Unsupported OS family '{0}'".format( OSCheck.get_os_family()))
def getAvaliableAgentPackageVersions(): if OSCheck.is_suse_family(): Command = ["bash", "-c", "zypper --no-gpg-checks -q search -s --match-exact ambari-agent | grep ambari-agent | sed -re 's/\s+/ /g' | cut -d '|' -f 4 | tr '\\n' ', ' | sed -s 's/[-|~][A-Za-z0-9]*//g'"] elif OSCheck.is_ubuntu_family(): Command = ["bash", "-c", "apt-cache -q show ambari-agent|grep 'Version\:'|cut -d ' ' -f 2| tr '\\n' ', '|sed -s 's/[-|~][A-Za-z0-9]*//g'"] else: Command = ["bash", "-c", "yum -q list all ambari-agent | grep -E '^ambari-agent' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | tr '\\n' ', ' | sed -s 's/[-|~][A-Za-z0-9]*//g'"] return execOsCommand(Command)
def installAgent(projectVersion): """ Run install and make sure the agent install alright """ # The command doesn't work with file mask ambari-agent*.rpm, so rename it on agent host if OSCheck.is_suse_family(): Command = ["zypper", "install", "-y", "ambari-agent-" + projectVersion] elif OSCheck.is_debian_family(): # add * to end of version in case of some test releases Command = ["apt-get", "install", "-y", "--force-yes", "ambari-agent=" + projectVersion + "*"] else: Command = ["yum", "-y", "install", "--nogpgcheck", "ambari-agent-" + projectVersion] return execOsCommand(Command)
def installAgent(projectVersion): """ Run install and make sure the agent install alright """ # The command doesn't work with file mask ambari-agent*.rpm, so rename it on agent host if OSCheck.is_suse_family(): Command = ["zypper", "--no-gpg-checks", "install", "-y", "ambari-agent-" + projectVersion] elif OSCheck.is_ubuntu_family(): # add * to end of version in case of some test releases Command = ["apt-get", "install", "-y", "--allow-unauthenticated", "ambari-agent=" + projectVersion + "*"] else: Command = ["yum", "-y", "install", "--nogpgcheck", "ambari-agent-" + projectVersion] return execOsCommand(Command, tries=3, try_sleep=10)
def configure_database(self, properties, options): result = self._prompt_db_properties() if result: #DB setup should be done last after doing any setup. if self._is_local_database(): self._setup_local_server(properties, options) # this issue appears only for Suse. Postgres need /var/run/postgresql dir but do not create it if OSCheck.is_suse_family(): self._create_postgres_lock_directory() else: self._setup_remote_server(properties, options) return result
def configure_database(self, properties): result = self._prompt_db_properties() if result: #DB setup should be done last after doing any setup. if self._is_local_database(): self._setup_local_server(properties) # this issue appears only for Suse. Postgres need /var/run/postgresql dir but do not create it if OSCheck.is_suse_family(): self._create_postgres_lock_directory() else: self._setup_remote_server(properties) return result
def allAvailablePackages(allAvailablePackages): osType = OSCheck.get_os_family() if OSCheck.is_suse_family(): return _lookUpZypperPackages( ["sudo", "zypper", "search", "--uninstalled-only", "--details"], allAvailablePackages) elif OSCheck.is_redhat_family(): return _lookUpYumPackages(["sudo", "yum", "list", "available"], 'Available Packages', allAvailablePackages) elif OSCheck.is_ubuntu_family(): return _lookUpAptPackages(LIST_AVAILABLE_PACKAGES_UBUNTU, allAvailablePackages)
def installAgent(projectVersion, ret=None): """ Run install and make sure the agent install alright """ # The command doesn't work with file mask ambari-agent*.rpm, so rename it on agent host if OSCheck.is_suse_family(): Command = ["zypper", "--no-gpg-checks", "install", "-y", "ambari-agent-" + projectVersion] elif OSCheck.is_ubuntu_family(): # add * to end of version in case of some test releases Command = ["apt-get", "install", "-y", "--allow-unauthenticated", "ambari-agent=" + projectVersion + "*"] elif OSCheck.is_windows_family(): packageParams = "/AmbariRoot:" + AMBARI_INSTALL_ROOT Command = ["cmd", "/c", "choco", "install", "-y", "ambari-agent", "--version=" + projectVersion, "--params=\"" + packageParams + "\""] else: Command = ["yum", "-y", "install", "--nogpgcheck", "ambari-agent-" + projectVersion] return execOsCommand(Command, tries=3, try_sleep=10, ret=ret)
def get_ambari_repo_file_full_name(): if OSCheck.is_ubuntu_family(): ambari_repo_file = "/etc/apt/sources.list.d/ambari.list" elif OSCheck.is_redhat_family(): ambari_repo_file = "/etc/yum.repos.d/ambari.repo" elif OSCheck.is_suse_family(): ambari_repo_file = "/etc/zypp/repos.d/ambari.repo" elif OSCheck.is_windows_family(): ambari_repo_file = os.path.join(os.environ[ChocolateyConsts.CHOCOLATEY_INSTALL_VAR_NAME], ChocolateyConsts.CHOCOLATEY_CONFIG_DIR, ChocolateyConsts.CHOCOLATEY_CONFIG_FILENAME) else: raise Exception('Ambari repo file path not set for current OS.') return ambari_repo_file
def allAvailablePackages(allAvailablePackages): if OSCheck.is_suse_family(): return _lookUpZypperPackages([ AMBARI_SUDO_BINARY, "zypper", "--no-gpg-checks", "search", "--uninstalled-only", "--details" ], allAvailablePackages) elif OSCheck.is_redhat_family(): return _lookUpYumPackages( [AMBARI_SUDO_BINARY, "yum", "list", "available"], 'Available Packages', allAvailablePackages) elif OSCheck.is_ubuntu_family(): return _lookUpAptPackages( LIST_AVAILABLE_PACKAGES_UBUNTU % GREP_REPO_EXCLUDE_SYSTEM, allAvailablePackages)
def allInstalledPackages(allInstalledPackages): """ All installed packages in system """ osType = OSCheck.get_os_family() if OSCheck.is_suse_family(): return _lookUpZypperPackages( ["sudo", "zypper", "search", "--installed-only", "--details"], allInstalledPackages) elif OSCheck.is_redhat_family(): return _lookUpYumPackages(["sudo", "yum", "list", "installed"], 'Installed Packages', allInstalledPackages) elif OSCheck.is_ubuntu_family(): return _lookUpAptPackages(LIST_INSTALLED_PACKAGES_UBUNTU, allInstalledPackages)
def allInstalledPackages(allInstalledPackages): """ All installed packages in system """ if OSCheck.is_suse_family(): return _lookUpZypperPackages([ AMBARI_SUDO_BINARY, "zypper", "--no-gpg-checks", "search", "--installed-only", "--details" ], allInstalledPackages) elif OSCheck.is_redhat_family(): return _lookUpYumPackages( [AMBARI_SUDO_BINARY, "yum", "list", "installed"], 'Installed Packages', allInstalledPackages) elif OSCheck.is_ubuntu_family(): return _lookUpAptPackages(LIST_INSTALLED_PACKAGES_UBUNTU, allInstalledPackages)
def allAvailablePackages(allAvailablePackages): osType = OSCheck.get_os_family() if OSCheck.is_suse_family(): return _lookUpZypperPackages( ["sudo", "zypper", "search", "--uninstalled-only", "--details"], allAvailablePackages) elif OSCheck.is_redhat_family(): return _lookUpYumPackages( ["sudo", "yum", "list", "available"], 'Available Packages', allAvailablePackages) elif OSCheck.is_ubuntu_family(): return _lookUpAptPackages( LIST_AVAILABLE_PACKAGES_UBUNTU, allAvailablePackages)
def findNearestAgentPackageVersion(projectVersion): if projectVersion == "": projectVersion = " " if OSCheck.is_suse_family(): Command = ["bash", "-c", "zypper --no-gpg-checks -q search -s --match-exact ambari-agent | grep '" + projectVersion + "' | cut -d '|' -f 4 | head -n1 | sed -e 's/-\w[^:]*//1' "] elif OSCheck.is_ubuntu_family(): if projectVersion == " ": Command = ["bash", "-c", "apt-cache -q show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|tr -d '\\n'|sed -s 's/[-|~][A-Za-z0-9]*//'"] else: Command = ["bash", "-c", "apt-cache -q show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|grep '" + projectVersion + "'|tr -d '\\n'|sed -s 's/[-|~][A-Za-z0-9]*//'"] else: Command = ["bash", "-c", "yum -q list all ambari-agent | grep '" + projectVersion + "' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | head -n1 | sed -e 's/-\w[^:]*//1' "] return execOsCommand(Command)
def get_available_packages_in_repos(repositories): """ Gets all (both installed and available) packages that are available at given repositories. :param repositories: from command configs like config['repositoryFile']['repositories'] :return: installed and available packages from these repositories """ available_packages = [] installed_packages = [] available_packages_in_repos = [] repo_ids = [repository['repoId'] for repository in repositories] if OSCheck.is_ubuntu_family(): allInstalledPackages(installed_packages) repo_urls = [repository['baseUrl'] for repository in repositories] repo_urls = [repo_url.replace("http://", "") for repo_url in repo_urls] repo_urls = [repo_url.replace("/", "_") for repo_url in repo_urls] for url in repo_urls: _lookUpAptPackages(LIST_AVAILABLE_PACKAGES_UBUNTU % url, available_packages) for package in installed_packages: if url in package[2]: available_packages_in_repos.append(package[0]) for package in available_packages: available_packages_in_repos.append(package[0]) elif OSCheck.is_suse_family(): for repo in repo_ids: _lookUpZypperPackages([ AMBARI_SUDO_BINARY, "zypper", "--no-gpg-checks", "search", "--details", "--repo", repo ], available_packages) available_packages_in_repos += [ package[0] for package in available_packages ] elif OSCheck.is_redhat_family(): for repo in repo_ids: _lookUpYumPackages([ AMBARI_SUDO_BINARY, "yum", "list", "available", "--disablerepo=*", "--enablerepo=" + repo ], 'Available Packages', available_packages) _lookUpYumPackages([ AMBARI_SUDO_BINARY, "yum", "list", "installed", "--disablerepo=*", "--enablerepo=" + repo ], 'Installed Packages', installed_packages) available_packages_in_repos += [ package[0] for package in available_packages + installed_packages ] return available_packages_in_repos
def installAgent(projectVersion): """ Run install and make sure the agent install alright """ # The command doesn't work with file mask ambari-agent*.rpm, so rename it on agent host if OSCheck.is_suse_family(): Command = ["zypper", "install", "-y", "ambari-agent-" + projectVersion] elif OSCheck.is_debian_family(): # add * to end of version in case of some test releases Command = [ "apt-get", "install", "-y", "--force-yes", "ambari-agent=" + projectVersion + "*" ] else: Command = [ "yum", "-y", "install", "--nogpgcheck", "ambari-agent-" + projectVersion ] return execOsCommand(Command)
def getAvaliableAgentPackageVersions(): if OSCheck.is_suse_family(): Command = [ "bash", "-c", "zypper -q search -s --match-exact ambari-agent | grep ambari-agent | sed -re 's/\s+/ /g' | cut -d '|' -f 4 | tr '\\n' ', ' | sed -s 's/[-|~][A-Za-z0-9]*//g'" ] elif OSCheck.is_debian_family(): Command = [ "bash", "-c", "apt-cache -q show ambari-agent|grep 'Version\:'|cut -d ' ' -f 2| tr '\\n' ', '|sed -s 's/[-|~][A-Za-z0-9]*//g'" ] else: Command = [ "bash", "-c", "yum -q list all ambari-agent | grep -E '^ambari-agent' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | tr '\\n' ', ' | sed -s 's/[-|~][A-Za-z0-9]*//g'" ] return execOsCommand(Command)
def _check_postgre_up(): pg_status, retcode, out, err = PGConfig._get_postgre_status() if pg_status == PGConfig.PG_STATUS_RUNNING: print_info_msg("PostgreSQL is running") return pg_status, 0, out, err else: # run initdb only on non ubuntu systems as ubuntu does not have initdb cmd. if not OSCheck.is_ubuntu_family(): print "Running initdb: This may take upto a minute." retcode, out, err = run_os_command(PGConfig.PG_INITDB_CMD) if retcode == 0: print out print "About to start PostgreSQL" try: process = subprocess.Popen(PGConfig.PG_START_CMD.split(' '), stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) if OSCheck.is_suse_family(): time.sleep(20) result = process.poll() print_info_msg("Result of postgres start cmd: " + str(result)) if result is None: process.kill() pg_status, retcode, out, err = PGConfig._get_postgre_status( ) else: retcode = result else: out, err = process.communicate() retcode = process.returncode pg_status, retcode, out, err = PGConfig._get_postgre_status( ) if pg_status == PGConfig.PG_STATUS_RUNNING: print_info_msg("Postgres process is running. Returning...") return pg_status, 0, out, err except (Exception), e: pg_status, retcode, out, err = PGConfig._get_postgre_status() if pg_status == PGConfig.PG_STATUS_RUNNING: return pg_status, 0, out, err else: print_error_msg("Postgres start failed. " + str(e)) return pg_status, retcode, out, err
def allInstalledPackages(allInstalledPackages): """ All installed packages in system """ osType = OSCheck.get_os_family() if OSCheck.is_suse_family(): return _lookUpZypperPackages( ["sudo", "zypper", "search", "--installed-only", "--details"], allInstalledPackages) elif OSCheck.is_redhat_family(): return _lookUpYumPackages( ["sudo", "yum", "list", "installed"], 'Installed Packages', allInstalledPackages) elif OSCheck.is_ubuntu_family(): return _lookUpAptPackages( LIST_INSTALLED_PACKAGES_UBUNTU, allInstalledPackages)
def _check_postgre_up(): pg_status, retcode, out, err = PGConfig._get_postgre_status() if pg_status == PGConfig.PG_STATUS_RUNNING: print_info_msg("PostgreSQL is running") return pg_status, 0, out, err else: # run initdb only on non ubuntu systems as ubuntu does not have initdb cmd. if not OSCheck.is_ubuntu_family(): print "Running initdb: This may take upto a minute." retcode, out, err = run_os_command(PGConfig.PG_INITDB_CMD) if retcode == 0: print out print "About to start PostgreSQL" try: process = subprocess.Popen(PGConfig.PG_START_CMD.split(' '), stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE ) if OSCheck.is_suse_family(): time.sleep(20) result = process.poll() print_info_msg("Result of postgres start cmd: " + str(result)) if result is None: process.kill() pg_status, retcode, out, err = PGConfig._get_postgre_status() else: retcode = result else: out, err = process.communicate() retcode = process.returncode pg_status, retcode, out, err = PGConfig._get_postgre_status() if pg_status == PGConfig.PG_STATUS_RUNNING: print_info_msg("Postgres process is running. Returning...") return pg_status, 0, out, err except (Exception), e: pg_status, retcode, out, err = PGConfig._get_postgre_status() if pg_status == PGConfig.PG_STATUS_RUNNING: return pg_status, 0, out, err else: print_error_msg("Postgres start failed. " + str(e)) return pg_status, retcode, out, err
def installAgent(projectVersion): """ Run install and make sure the agent install alright """ # The command doesn't work with file mask ambari-agent*.rpm, so rename it on agent host if OSCheck.is_suse_family(): Command = [ "zypper", "--no-gpg-checks", "install", "-y", "ambari-agent-" + projectVersion ] elif OSCheck.is_ubuntu_family(): # add * to end of version in case of some test releases Command = [ "apt-get", "install", "-y", "--allow-unauthenticated", "ambari-agent=" + projectVersion + "*" ] else: Command = [ "yum", "-y", "install", "--nogpgcheck", "ambari-agent-" + projectVersion ] return execOsCommand(Command, tries=3, try_sleep=10)
def findNearestAgentPackageVersion(projectVersion): if projectVersion == "": projectVersion = " " if OSCheck.is_suse_family(): Command = ["bash", "-c", "zypper --no-gpg-checks -q search -s --match-exact ambari-agent | grep '" + projectVersion + "' | cut -d '|' -f 4 | head -n1 | sed -e 's/-\w[^:]*//1' "] elif OSCheck.is_windows_family(): listPackagesCommand = ["cmd", "/c", "choco list ambari-agent --pre --all | findstr " + projectVersion + " > agentPackages.list"] execOsCommand(listPackagesCommand) Command = ["cmd", "/c", "powershell", "get-content agentPackages.list | select-object -last 1 | foreach-object {$_ -replace 'ambari-agent ', ''}"] elif OSCheck.is_ubuntu_family(): if projectVersion == " ": Command = ["bash", "-c", "apt-cache -q show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|tr -d '\\n'|sed -s 's/[-|~][A-Za-z0-9]*//'"] else: Command = ["bash", "-c", "apt-cache -q show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|grep '" + projectVersion + "'|tr -d '\\n'|sed -s 's/[-|~][A-Za-z0-9]*//'"] else: Command = ["bash", "-c", "yum -q list all ambari-agent | grep '" + projectVersion + "' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | head -n1 | sed -e 's/-\w[^:]*//1' "] return execOsCommand(Command)
def findNearestAgentPackageVersion(projectVersion): if projectVersion == "": projectVersion = " " if OSCheck.is_suse_family(): Command = [ "bash", "-c", "zypper --no-gpg-checks --non-interactive -q search -s --match-exact ambari-agent | grep '" + projectVersion + "' | cut -d '|' -f 4 | head -n1 | sed -e 's/-\w[^:]*//1' " ] elif OSCheck.is_windows_family(): listPackagesCommand = [ "cmd", "/c", "choco list ambari-agent --pre --all | findstr " + projectVersion + " > agentPackages.list" ] execOsCommand(listPackagesCommand) Command = [ "cmd", "/c", "powershell", "get-content agentPackages.list | select-object -last 1 | foreach-object {$_ -replace 'ambari-agent ', ''}" ] elif OSCheck.is_ubuntu_family(): if projectVersion == " ": Command = [ "bash", "-c", "apt-cache -q show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|tr -d '\\n'|sed -s 's/[-|~][A-Za-z0-9]*//'" ] else: Command = [ "bash", "-c", "apt-cache -q show ambari-agent |grep 'Version\:'|cut -d ' ' -f 2|grep '" + projectVersion + "'|tr -d '\\n'|sed -s 's/[-|~][A-Za-z0-9]*//'" ] else: Command = [ "bash", "-c", "yum -q list all ambari-agent | grep '" + projectVersion + "' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | head -n1 | sed -e 's/-\w[^:]*//1' " ] return execOsCommand(Command)
def getAvailableAgentPackageVersions(): if OSCheck.is_suse_family(): Command = [ "bash", "-c", "zypper --no-gpg-checks --non-interactive -q search -s --match-exact ambari-agent | grep ambari-agent | sed -re 's/\s+/ /g' | cut -d '|' -f 4 | tr '\\n' ', ' | sed -s 's/[-|~][A-Za-z0-9]*//g'" ] elif OSCheck.is_windows_family(): Command = [ "cmd", "/c", "choco list ambari-agent --pre --all | findstr ambari-agent" ] elif OSCheck.is_ubuntu_family(): Command = [ "bash", "-c", "apt-cache -q show ambari-agent|grep 'Version\:'|cut -d ' ' -f 2| tr '\\n' ', '|sed -s 's/[-|~][A-Za-z0-9]*//g'" ] else: Command = [ "bash", "-c", "yum -q list all ambari-agent | grep -E '^ambari-agent' | sed -re 's/\s+/ /g' | cut -d ' ' -f 2 | tr '\\n' ', ' | sed -s 's/[-|~][A-Za-z0-9]*//g'" ] return execOsCommand(Command)
hive_metastore_win_service_name = "metastore" hive_client_win_service_name = "hwi" hive_server_win_service_name = "hiveserver2" webhcat_server_win_service_name = "templeton" else: hive_pid_dir = config['configurations']['hive-env']['hive_pid_dir'] hive_pid = 'hive-server.pid' hive_interactive_pid = 'hive-interactive.pid' hive_metastore_pid = 'hive.pid' hcat_pid_dir = config['configurations']['hive-env'][ 'hcat_pid_dir'] #hcat_pid_dir webhcat_pid_file = format('{hcat_pid_dir}/webhcat.pid') process_name = 'mysqld' if OSCheck.is_suse_family() or OSCheck.is_ubuntu_family(): daemon_name = 'mysql' else: daemon_name = 'mysqld' # Security related/required params hostname = config['hostname'] security_enabled = config['configurations']['cluster-env'][ 'security_enabled'] kinit_path_local = get_kinit_path( default('/configurations/kerberos-env/executable_search_paths', None)) tmp_dir = Script.get_tmp_dir() hdfs_user = config['configurations']['hadoop-env']['hdfs_user'] hive_user = config['configurations']['hive-env']['hive_user'] webhcat_user = config['configurations']['hive-env']['webhcat_user']
def get_ntp_service(): if OSCheck.is_redhat_family(): return "ntpd" elif OSCheck.is_suse_family() or OSCheck.is_ubuntu_family(): return "ntp"
def get_repo_dir(): if OSCheck.is_redhat_family(): return '/etc/yum.repos.d' elif OSCheck.is_suse_family(): return '/etc/zypp/repos.d'
if OSCheck.is_windows_family(): hive_metastore_win_service_name = "metastore" hive_client_win_service_name = "hwi" hive_server_win_service_name = "hiveserver2" webhcat_server_win_service_name = "templeton" else: hive_pid_dir = config['configurations']['hive-env']['hive_pid_dir'] hive_pid = 'hive-server.pid' hive_metastore_pid = 'hive.pid' hcat_pid_dir = config['configurations']['hive-env']['hcat_pid_dir'] #hcat_pid_dir webhcat_pid_file = format('{hcat_pid_dir}/webhcat.pid') process_name = 'mysqld' if OSCheck.is_suse_family() or OSCheck.is_ubuntu_family(): daemon_name = 'mysql' else: daemon_name = 'mysqld' # Security related/required params hostname = config['hostname'] security_enabled = config['configurations']['cluster-env']['security_enabled'] kinit_path_local = get_kinit_path(default('/configurations/kerberos-env/executable_search_paths', None)) tmp_dir = Script.get_tmp_dir() hdfs_user = config['configurations']['hadoop-env']['hdfs_user'] hive_user = config['configurations']['hive-env']['hive_user'] webhcat_user = config['configurations']['hive-env']['webhcat_user'] # default configuration directories hadoop_conf_dir = conf_select.get_hadoop_conf_dir()