def _link_configs(package, version, old_conf, link_conf):
  """
  Link a specific package's configuration directory
  """

  if not os.path.exists(old_conf):
    Logger.debug("Skipping {0} as it does not exist.".format(old_conf))
    return

  # check if conf is a link to the target already
  if os.path.islink(old_conf):
    Logger.debug("{0} is already a link to {1}".format(old_conf, os.path.realpath(old_conf)))
    return

  # make backup dir and copy everything in case configure() was called after install()
  old_parent = os.path.abspath(os.path.join(old_conf, os.pardir))
  old_conf_copy = os.path.join(old_parent, "conf.install")
  Execute(("cp", "-R", "-p", old_conf, old_conf_copy),
          not_if = format("test -e {old_conf_copy}"),
          sudo = True,
  )

  versioned_conf = conf_select.create("HDP", package, version, dry_run = True)

  Logger.info("New conf directory is {0}".format(versioned_conf))

  # make new conf dir and copy everything in case configure() was called after install()
  if not os.path.exists(versioned_conf):
    conf_select.create("HDP", package, version)
    Execute(as_sudo(["cp", "-R", "-p", os.path.join(old_conf, "*"), versioned_conf], auto_escape=False),
            only_if = format("ls {old_conf}/*")
    )
    
  # make /usr/hdp/<version>/hadoop/conf point to the versioned config.
  # /usr/hdp/current is already set
  conf_select.select("HDP", package, version)

  # no more references to /etc/[component]/conf
  Directory(old_conf,
    action="delete",
  )

  # link /etc/[component]/conf -> /usr/hdp/current/[component]-client/conf
  Link(old_conf,
    to = link_conf
  )
Esempio n. 2
0
  def test_create_seeds_configuration_directories(self, shell_call_mock):
    """
    Tests that conf-select seeds new directories
    :return:
    """

    def mock_call(command, **kwargs):
      """
      Instead of shell.call, call a command whose output equals the command.
      :param command: Command that will be echoed.
      :return: Returns a tuple of (process output code, stdout, stderr)
      """
      return (0, "/etc/foo/conf", None)

    shell_call_mock.side_effect = mock_call
    conf_select.create("HDP", "oozie", "version")

    self.assertEqual(pprint.pformat(self.env.resource_list),
      "[Directory['/etc/foo/conf'],\n "
      "Execute['ambari-sudo.sh [RMF_ENV_PLACEHOLDER] -H -E cp -R -p -v /usr/hdp/current/oozie-client/conf/* /etc/foo/conf']]")
Esempio n. 3
0
  def pre_upgrade_conf41(self, env):
    """
    Create /etc/solr/4.1.0.0/0 directory and copies Solr config files here.
    Create symlinks accordingly.

    conf-select create-conf-dir --package solr --stack-version 4.1.0.0 --conf-version 0
    cp -r /usr/iop/4.1.0.0/solr/conf/* /etc/solr/4.1.0.0/0/.
    unlink or rm -r /usr/iop/4.1.0.0/solr/conf
    ln -s /etc/solr/4.1.0.0/0 /usr/iop/4.1.0.0/solr/conf
    conf-select set-conf-dir --package solr --stack-version 4.1.0.0 --conf-version 0
    """
    import params
    env.set_params(params)

    solr41_conf_dir="/usr/iop/4.1.0.0/solr/conf"
    solr41_etc_dir="/etc/solr/4.1.0.0/0"
    if not os.path.exists(solr41_etc_dir):
      conf_select.create(params.stack_name, "solr", "4.1.0.0")

    content_path=solr41_conf_dir
    if not os.path.isfile("/usr/iop/4.1.0.0/solr/conf/solr.in.sh"):
      content_path = "/etc/solr/conf.backup"

    for each in os.listdir(content_path):
      File(os.path.join(solr41_etc_dir, each),
           owner=params.solr_user,
           content = StaticFile(os.path.join(content_path, each)))

    if not os.path.islink(solr41_conf_dir):
      Directory(solr41_conf_dir,
                action="delete",
                create_parents=True)

    if os.path.islink(solr41_conf_dir):
      os.unlink(solr41_conf_dir)

    if not os.path.islink(solr41_conf_dir):
      Link(solr41_conf_dir,
           to=solr41_etc_dir
      )
Esempio n. 4
0
def _link_configs(package, version, dirs):
    """
  Link a specific package's configuration directory
  """
    bad_dirs = []
    for dir_def in dirs:
        if not os.path.exists(dir_def['conf_dir']):
            bad_dirs.append(dir_def['conf_dir'])

    if len(bad_dirs) > 0:
        Logger.debug("Skipping {0} as it does not exist.".format(
            ",".join(bad_dirs)))
        return

    bad_dirs = []
    for dir_def in dirs:
        # check if conf is a link already
        old_conf = dir_def['conf_dir']
        if os.path.islink(old_conf):
            Logger.debug("{0} is a link to {1}".format(
                old_conf, os.path.realpath(old_conf)))
            bad_dirs.append(old_conf)

    if len(bad_dirs) > 0:
        return

    # make backup dir and copy everything in case configure() was called after install()
    for dir_def in dirs:
        old_conf = dir_def['conf_dir']
        old_parent = os.path.abspath(os.path.join(old_conf, os.pardir))
        old_conf_copy = os.path.join(old_parent, "conf.install")
        Execute(("cp", "-R", "-p", old_conf, old_conf_copy),
                not_if=format("test -e {old_conf_copy}"),
                sudo=True)

    # we're already in the HDP stack
    versioned_confs = conf_select.create("HDP", package, version, dry_run=True)

    Logger.info("New conf directories: {0}".format(", ".join(versioned_confs)))

    need_dirs = []
    for d in versioned_confs:
        if not os.path.exists(d):
            need_dirs.append(d)

    if len(need_dirs) > 0:
        conf_select.create("HDP", package, version)

        # find the matching definition and back it up (not the most efficient way) ONLY if there is more than one directory
        if len(dirs) > 1:
            for need_dir in need_dirs:
                for dir_def in dirs:
                    if 'prefix' in dir_def and need_dir.startswith(
                            dir_def['prefix']):
                        old_conf = dir_def['conf_dir']
                        versioned_conf = need_dir
                        Execute(as_sudo([
                            "cp", "-R", "-p",
                            os.path.join(old_conf, "*"), versioned_conf
                        ],
                                        auto_escape=False),
                                only_if=format("ls {old_conf}/*"))
        elif 1 == len(dirs) and 1 == len(need_dirs):
            old_conf = dirs[0]['conf_dir']
            versioned_conf = need_dirs[0]
            Execute(as_sudo([
                "cp", "-R", "-p",
                os.path.join(old_conf, "*"), versioned_conf
            ],
                            auto_escape=False),
                    only_if=format("ls {old_conf}/*"))

    # make /usr/hdp/[version]/[component]/conf point to the versioned config.
    # /usr/hdp/current is already set
    try:
        conf_select.select("HDP", package, version)

        # no more references to /etc/[component]/conf
        for dir_def in dirs:
            Directory(dir_def['conf_dir'], action="delete")

            # link /etc/[component]/conf -> /usr/hdp/current/[component]-client/conf
            Link(dir_def['conf_dir'], to=dir_def['current_dir'])
    except Exception, e:
        Logger.warning("Could not select the directory: {0}".format(e.message))
def _link_configs(package, version, dirs):
  """
  Link a specific package's configuration directory
  """
  bad_dirs = []
  for dir_def in dirs:
    if not os.path.exists(dir_def['conf_dir']):
      bad_dirs.append(dir_def['conf_dir'])

  if len(bad_dirs) > 0:
    Logger.debug("Skipping {0} as it does not exist.".format(",".join(bad_dirs)))
    return

  bad_dirs = []
  for dir_def in dirs:
    # check if conf is a link already
    old_conf = dir_def['conf_dir']
    if os.path.islink(old_conf):
      Logger.debug("{0} is a link to {1}".format(old_conf, os.path.realpath(old_conf)))
      bad_dirs.append(old_conf)

  if len(bad_dirs) > 0:
    return

  # make backup dir and copy everything in case configure() was called after install()
  for dir_def in dirs:
    old_conf = dir_def['conf_dir']
    old_parent = os.path.abspath(os.path.join(old_conf, os.pardir))
    old_conf_copy = os.path.join(old_parent, "conf.install")
    Execute(("cp", "-R", "-p", old_conf, old_conf_copy),
      not_if = format("test -e {old_conf_copy}"), sudo = True)

  # we're already in the HDP stack
  versioned_confs = conf_select.create("HDP", package, version, dry_run = True)

  Logger.info("New conf directories: {0}".format(", ".join(versioned_confs)))

  need_dirs = []
  for d in versioned_confs:
    if not os.path.exists(d):
      need_dirs.append(d)

  if len(need_dirs) > 0:
    conf_select.create("HDP", package, version)

    # find the matching definition and back it up (not the most efficient way) ONLY if there is more than one directory
    if len(dirs) > 1:
      for need_dir in need_dirs:
        for dir_def in dirs:
          if 'prefix' in dir_def and need_dir.startswith(dir_def['prefix']):
            old_conf = dir_def['conf_dir']
            versioned_conf = need_dir
            Execute(as_sudo(["cp", "-R", "-p", os.path.join(old_conf, "*"), versioned_conf], auto_escape=False),
              only_if = format("ls {old_conf}/*"))
    elif 1 == len(dirs) and 1 == len(need_dirs):
      old_conf = dirs[0]['conf_dir']
      versioned_conf = need_dirs[0]
      Execute(as_sudo(["cp", "-R", "-p", os.path.join(old_conf, "*"), versioned_conf], auto_escape=False),
        only_if = format("ls {old_conf}/*"))


  # make /usr/hdp/[version]/[component]/conf point to the versioned config.
  # /usr/hdp/current is already set
  try:
    conf_select.select("HDP", package, version)

    # no more references to /etc/[component]/conf
    for dir_def in dirs:
      Directory(dir_def['conf_dir'], action="delete")

      # link /etc/[component]/conf -> /usr/hdp/current/[component]-client/conf
      Link(dir_def['conf_dir'], to = dir_def['current_dir'])
  except Exception, e:
    Logger.warning("Could not select the directory: {0}".format(e.message))