Esempio n. 1
0
def mount_and_run(log, workspace, host, host_iso_path, config, funct,
                  arg):
    """
    Mount the ISO and run a funct
    """
    # pylint: disable=bare-except,too-many-arguments
    mnt_path = "/mnt/" + utils.random_word(8)

    command = ("mkdir -p %s && mount -o loop %s %s" %
               (mnt_path, host_iso_path, mnt_path))
    retval = host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error("failed to run command [%s] on host [%s], "
                     "ret = [%d], stdout = [%s], stderr = [%s]",
                     command,
                     host.sh_hostname,
                     retval.cr_exit_status,
                     retval.cr_stdout,
                     retval.cr_stderr)
        return -1

    try:
        ret = funct(log, workspace, host, mnt_path, config, arg)
    except:
        ret = -1
        log.cl_error("exception: %s", traceback.format_exc())

    command = ("umount %s" % (mnt_path))
    retval = host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error("failed to run command [%s] on host [%s], "
                     "ret = [%d], stdout = [%s], stderr = [%s]",
                     command,
                     host.sh_hostname,
                     retval.cr_exit_status,
                     retval.cr_stdout,
                     retval.cr_stderr)
        ret = -1

    command = ("rmdir %s" % (mnt_path))
    retval = host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error("failed to run command [%s] on host [%s], "
                     "ret = [%d], stdout = [%s], stderr = [%s]",
                     command,
                     host.sh_hostname,
                     retval.cr_exit_status,
                     retval.cr_stdout,
                     retval.cr_stderr)
        return -1
    return ret
Esempio n. 2
0
def check_hsm_copytool_storage(log, copytools):
    """
    Check the HSM storage status of copytools
    """
    random_fpaths = []
    for copytool_id, copytool in copytools.iteritems():
        random_fpath = copytool.hc_hsm_root + "/" + utils.random_word(8)
        command = "touch %s" % random_fpath
        retval = copytool.hc_host.sh_run(log, command)
        if retval.cr_exit_status:
            log.cl_error("failed to run command [%s] on copytool host [%s], "
                         "ret = [%d], "
                         "stdout = [%s], stderr = [%s]",
                         command,
                         copytool_id,
                         retval.cr_exit_status,
                         retval.cr_stdout,
                         retval.cr_stderr)
            return -1
        random_fpaths.append(random_fpath)

    for random_fpath in random_fpaths:
        for copytool_id, copytool in copytools.iteritems():
            command = "ls %s" % random_fpath
            retval = copytool.hc_host.sh_run(log, command)
            if retval.cr_exit_status:
                log.cl_error("failed to run command [%s] on copytool "
                             "host [%s], ret = [%d], "
                             "stdout = [%s], stderr = [%s]",
                             command,
                             copytool_id,
                             retval.cr_exit_status,
                             retval.cr_stdout,
                             retval.cr_stderr)
                return -1
        copytool = copytools.values()[0]
        command = "rm -f %s" % random_fpath
        retval = copytool.hc_host.sh_run(log, command)
        if retval.cr_exit_status:
            log.cl_error("failed to run command [%s] on copytool host "
                         "[%s], ret = [%d], "
                         "stdout = [%s], stderr = [%s]",
                         command,
                         copytool_id,
                         retval.cr_exit_status,
                         retval.cr_stdout,
                         retval.cr_stderr)
            return -1
    return 0
Esempio n. 3
0
def dependency_install(log, host, config, rpms, name, iso_path_pattern):
    """
    Install the dependent RPMs
    """
    # pylint: disable=too-many-arguments
    if not os.path.exists(config):
        log.cl_error("config file [%s] doesn't exist", config)
        return -1

    if not os.path.isfile(config):
        log.cl_error("config file [%s] isn't a file", config)
        return -1

    iso_path = iso_path_in_config(log, host, config)
    if iso_path is None:
        iso_path = find_iso_path_in_cwd(log, host, iso_path_pattern)
        if iso_path is None:
            log.cl_error(
                "failed to find %s ISO under currect directory "
                "with pattern [%s]", name, iso_path_pattern)
            return -1
        log.cl_info(
            "no [%s] is configured, use [%s] under current "
            "directory", cstr.CSTR_ISO_PATH, iso_path)

    mnt_path = "/mnt/" + utils.random_word(8)
    command = ("mkdir -p %s && mount -o loop %s %s" %
               (mnt_path, iso_path, mnt_path))
    retval = host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error(
            "failed to run command [%s] on host [%s], "
            "ret = [%d], stdout = [%s], stderr = [%s]", command,
            host.sh_hostname, retval.cr_exit_status, retval.cr_stdout,
            retval.cr_stderr)
        return -1

    repo_config_fpath = ("/tmp/%s.repo" % (name))
    packages_dir = mnt_path + "/" + cstr.CSTR_PACKAGES
    generate_repo_file(repo_config_fpath, packages_dir, name)
    ret = yum_repo_install(log, host, repo_config_fpath, rpms)
    if ret:
        log.cl_error(
            "failed to install dependency RPMs on from ISO at localhost")
        return -1

    command = ("umount %s" % (mnt_path))
    retval = host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error(
            "failed to run command [%s] on host [%s], "
            "ret = [%d], stdout = [%s], stderr = [%s]", command,
            host.sh_hostname, retval.cr_exit_status, retval.cr_stdout,
            retval.cr_stderr)
        ret = -1

    command = ("rmdir %s" % (mnt_path))
    retval = host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error(
            "failed to run command [%s] on host [%s], "
            "ret = [%d], stdout = [%s], stderr = [%s]", command,
            host.sh_hostname, retval.cr_exit_status, retval.cr_stdout,
            retval.cr_stderr)
        ret = -1
    return ret
def _iso_mount_and_install(log, workspace, config, config_fpath,
                           install_funct):
    """
    Mount the ISO and install the system
    """
    # pylint: disable=bare-except
    local_host = ssh_host.SSHHost("localhost", local=True)
    fname = utils.config_value(config, cstr.CSTR_ISO_PATH)
    if fname is None:
        fname = "clownfish-*.iso"
        iso_path = install_common.find_iso_path_in_cwd(log, local_host, fname)
        if iso_path is None:
            log.cl_error(
                "failed to find Clownfish ISO [%s] under currect "
                "directory", fname)
            return -1
        log.cl_info(
            "no [%s] is configured, use [%s] under current "
            "directory", cstr.CSTR_ISO_PATH, iso_path)
    else:
        # ISO could have wild card, find that
        iso_path = install_common.find_iso_path_in_cwd(log, local_host, fname)
        if iso_path is None:
            log.cl_error(
                "failed to find Clownfish ISO [%s] under currect "
                "directory", fname)
            return -1

    mnt_path = "/mnt/" + utils.random_word(8)

    command = ("mkdir -p %s && mount -o loop %s %s" %
               (mnt_path, iso_path, mnt_path))
    retval = local_host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error(
            "failed to run command [%s] on host [%s], "
            "ret = [%d], stdout = [%s], stderr = [%s]", command,
            local_host.sh_hostname, retval.cr_exit_status, retval.cr_stdout,
            retval.cr_stderr)
        return -1

    try:
        ret = install_funct(log, workspace, config, config_fpath, mnt_path,
                            iso_path, local_host)
    except:
        ret = -1
        log.cl_error("exception: %s", traceback.format_exc())

    command = ("umount %s" % (mnt_path))
    retval = local_host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error(
            "failed to run command [%s] on host [%s], "
            "ret = [%d], stdout = [%s], stderr = [%s]", command,
            local_host.sh_hostname, retval.cr_exit_status, retval.cr_stdout,
            retval.cr_stderr)
        ret = -1

    command = ("rmdir %s" % (mnt_path))
    retval = local_host.sh_run(log, command)
    if retval.cr_exit_status:
        log.cl_error(
            "failed to run command [%s] on host [%s], "
            "ret = [%d], stdout = [%s], stderr = [%s]", command,
            local_host.sh_hostname, retval.cr_exit_status, retval.cr_stdout,
            retval.cr_stderr)
        return -1
    return ret