Esempio n. 1
0
def lcreatemany_path(log):
    """
    Find the path of lcreatemany binary file
    """
    path = "src/lcreatemany"
    command = "test -x %s" % path
    retval = utils.run(command)
    if retval.cr_exit_status != 0:
        log.cl_info("failed to run command [%s]")
        path = "/usr/bin/lcreatemany"
        command = "test -x %s" % path
        retval = utils.run(command)
        if retval.cr_exit_status != 0:
            log.cl_error("no lcreatemany is found")
            return None
    return path
Esempio n. 2
0
def main():
    """
    Run the console
    """
    # pylint: disable=unused-variable
    now = time_util.utcnow()
    workspace = (LTEST_CONSOLE_LOG_DIR + "/" +
                 time_util.local_strftime(now, ('%Y-%m-%d-%H:%M:%S')))
    ret = utils.run("mkdir -p %s" % workspace)
    if ret.cr_exit_status != 0:
        logging.error("failed to create directory [%s]", workspace)
        sys.exit(1)

    log = clog.get_log(resultsdir=workspace)

    argc = len(sys.argv)
    if argc == 1:
        server = "http://localhost:1234"
    elif argc == 2:
        arg = sys.argv[1]
        if arg == "-h" or arg == "--help":
            usage()
            sys.exit(0)
        server = arg
        if not server.startswith("http://"):
            server = "http://" + server
        if server.count(":") != 2:
            server = server + ":" + str(ltest_scheduler.TEST_SCHEDULER_PORT)

    log.cl_info("connecting to server [%s]", server)
    proxy = xmlrpclib.ServerProxy(server, allow_none=True)

    tconsole_input_init()
    tconsole_input_loop(proxy)
    tconsole_input_fini()
Esempio n. 3
0
def clone_src_from_git(log,
                       build_dir,
                       git_url,
                       branch,
                       ssh_identity_file=None):
    """
    Get the Lustre soure codes from Git server.
    """
    command = ("rm -fr %s && mkdir -p %s && git init %s" %
               (build_dir, build_dir, build_dir))
    retval = utils.run(command)
    if retval.cr_exit_status != 0:
        log.cl_error(
            "failed to run command [%s], "
            "ret = [%d], stdout = [%s], stderr = [%s]", command,
            retval.cr_exit_status, retval.cr_stdout, retval.cr_stderr)
        return -1

    command = ("cd %s && git config remote.origin.url %s && "
               "GIT_SSH_COMMAND=\"ssh -i /root/.ssh/id_dsa\" "
               "git fetch --tags --progress %s "
               "+refs/heads/*:refs/remotes/origin/* && "
               "git checkout %s -f" % (build_dir, git_url, git_url, branch))
    if ssh_identity_file is not None:
        # Git 2.3.0+ has GIT_SSH_COMMAND
        command = ("ssh-agent sh -c 'ssh-add " + ssh_identity_file + " && " +
                   command + "'")

    retval = utils.run(command)
    if retval.cr_exit_status != 0:
        log.cl_error(
            "failed to run command [%s], "
            "ret = [%d], stdout = [%s], stderr = [%s]", command,
            retval.cr_exit_status, retval.cr_stdout, retval.cr_stderr)
        return -1
    return 0
Esempio n. 4
0
def main(default_config_fpath,
         default_log_parent,
         main_func,
         usage_func=None,
         parse_func=None,
         console_level=logging.INFO,
         lock=True):
    """
    The main function of a command
    """
    # pylint: disable=too-many-locals,too-many-branches,too-many-statements
    # pylint: disable=too-many-arguments
    reload(sys)
    sys.setdefaultencoding("utf-8")

    if parse_func is None:
        options, args = getopt.getopt(sys.argv[1:], "c:i:h",
                                      ["config=", "help", "logdir="])

        config_fpath = None
        workspace = None
        private = None
        for opt, arg in options:
            if opt == '-c' or opt == "--config" or opt == "-config":
                config_fpath = arg
            elif opt == '-l' or opt == "--logdir" or opt == "-logdir":
                workspace = arg
            elif opt == '-h' or opt == "--help" or opt == "-help":
                usage(usage_func)
                sys.exit(0)
            else:
                usage(usage_func)
                sys.exit(1)

        if len(args) != 0:
            usage(usage_func)
            sys.exit(1)
    else:
        workspace, config_fpath, private = parse_func()

    if workspace is None:
        identity = time_util.local_strftime(time_util.utcnow(),
                                            "%Y-%m-%d-%H_%M_%S")
        workspace = default_log_parent + "/" + identity
    if config_fpath is None:
        config_fpath = default_config_fpath

    command = "mkdir -p %s" % workspace
    retval = utils.run(command)
    if retval.cr_exit_status != 0:
        utils.eprint("failed to run command [%s], "
                     "ret = [%d], stdout = [%s], stderr = [%s]" %
                     (command, retval.cr_exit_status, retval.cr_stdout,
                      retval.cr_stderr))
        sys.exit(-1)

    log = clog.get_log(resultsdir=workspace,
                       exclusive=False,
                       console_level=console_level)
    log.cl_info("starting to run [%s] using config [%s], "
                "please check [%s] for more log" %
                (main_func.__name__, config_fpath, workspace))

    if not os.path.exists(config_fpath):
        log.cl_error("config [%s] doesn't exist, using empty config",
                     config_fpath)
        ret = main_func(log, workspace, None)
        sys.exit(ret)
    elif not os.path.isfile(config_fpath):
        log.cl_error("config [%s] is not a file", config_fpath)
        sys.exit(-1)

    config_fname = os.path.basename(config_fpath)
    save_fpath = workspace + "/" + config_fname
    log.cl_debug("copying config file from [%s] to [%s]", config_fpath,
                 save_fpath)
    if config_fpath != save_fpath:
        shutil.copyfile(config_fpath, save_fpath)

    if lock:
        lock_file = config_fpath + ".lock"
        lock = filelock.FileLock(lock_file)
        try:
            with lock.acquire(timeout=0):
                try:
                    if parse_func is None:
                        ret = main_func(log, workspace, config_fpath)
                    else:
                        ret = main_func(log, workspace, config_fpath, private)
                except:
                    ret = -1
                    log.cl_error("exception: %s", traceback.format_exc())
                lock.release()
        except filelock.Timeout:
            ret = -1
            log.cl_error(
                "someone else is holding lock of file [%s], aborting "
                "to prevent conflicts", lock_file)
    else:
        try:
            if parse_func is None:
                ret = main_func(log, workspace, config_fpath)
            else:
                ret = main_func(log, workspace, config_fpath, private)
        except:
            ret = -1
            log.cl_error("exception: %s", traceback.format_exc())
    sys.exit(ret)
Esempio n. 5
0
 def ping(self):
     """
     Check whether local host can ping this host
     """
     command = "ping -c 1 %s" % self.ln_hostname
     return utils.run(command)