Exemplo n.º 1
0
  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)
Exemplo n.º 2
0
  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)
Exemplo n.º 3
0
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",)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
  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
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
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
Exemplo n.º 10
0
  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
      )
Exemplo n.º 11
0
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",)
Exemplo n.º 12
0
 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()
Exemplo n.º 13
0
 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()
Exemplo n.º 14
0
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()))
Exemplo n.º 15
0
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()))
Exemplo n.º 16
0
 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()))
Exemplo n.º 17
0
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()))
Exemplo n.º 18
0
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()))
Exemplo n.º 19
0
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)
Exemplo n.º 20
0
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)
Exemplo n.º 21
0
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)
Exemplo n.º 22
0
 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
Exemplo n.º 23
0
 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
Exemplo n.º 24
0
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)
Exemplo n.º 25
0
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)
Exemplo n.º 26
0
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
Exemplo n.º 27
0
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
Exemplo n.º 28
0
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)
Exemplo n.º 29
0
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)
Exemplo n.º 30
0
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)
Exemplo n.º 32
0
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)
Exemplo n.º 33
0
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
Exemplo n.º 34
0
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)
Exemplo n.º 35
0
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)
Exemplo n.º 36
0
 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)
Exemplo n.º 38
0
 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
Exemplo n.º 39
0
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)
Exemplo n.º 40
0
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)
Exemplo n.º 41
0
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)
Exemplo n.º 42
0
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)
Exemplo n.º 43
0
    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']
Exemplo n.º 44
0
def get_ntp_service():
    if OSCheck.is_redhat_family():
        return "ntpd"
    elif OSCheck.is_suse_family() or OSCheck.is_ubuntu_family():
        return "ntp"
Exemplo n.º 45
0
def get_repo_dir():
    if OSCheck.is_redhat_family():
        return '/etc/yum.repos.d'
    elif OSCheck.is_suse_family():
        return '/etc/zypp/repos.d'
Exemplo n.º 46
0
def get_repo_dir():
  if OSCheck.is_redhat_family():
    return '/etc/yum.repos.d'
  elif OSCheck.is_suse_family():
    return '/etc/zypp/repos.d'
Exemplo n.º 47
0
def get_ntp_service():
  if OSCheck.is_redhat_family():
    return "ntpd"
  elif OSCheck.is_suse_family() or OSCheck.is_ubuntu_family():
    return "ntp"
Exemplo n.º 48
0
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()