Ejemplo n.º 1
0
def ssh_exec_script(vm_name, script_path):
    ssh.vm_scp_to_vm(vm_name, script_path)

    remote_path = hf.strip_top_dir(conf.top_dir, script_path)

    logger.info("Start %s", remote_path)

    script_name = os.path.splitext(os.path.basename(script_path))[0]
    prefix = host.get_next_prefix(conf.log_dir, "auto")
    log_name = "{}_{}.auto".format(prefix, script_name)
    log_path = os.path.join(conf.log_dir, log_name)
    try:
        ssh.vm_ssh(vm_name,
                   "bash {} && rm -vf {}".format(remote_path, remote_path),
                   log_file=log_path)
    except EnvironmentError:
        logger.error("Script failure: %s", script_name)
        sys.exit(1)

    logger.info("  done")
Ejemplo n.º 2
0
def ssh_exec_script(vm_name, script_path):
    ssh.vm_scp_to_vm(vm_name, script_path)

    remote_path = hf.strip_top_dir(conf.top_dir, script_path)

    logger.info("Start %s", remote_path)

    script_name = os.path.splitext(os.path.basename(script_path))[0]
    prefix = host.get_next_prefix(conf.log_dir, "auto")
    log_name = "{}_{}.auto".format(prefix, script_name)
    log_path = os.path.join(conf.log_dir, log_name)
    try:
        ssh.vm_ssh(vm_name,
                   "bash {} && rm -vf {}".format(remote_path, remote_path),
                   log_file=log_path)
    except EnvironmentError:
        logger.error("Script failure: %s", script_name)
        sys.exit(1)

    logger.info("  done")
Ejemplo n.º 3
0
def vm_scp_to_vm(vm_name, *args):
    """
    Copy files or directories (incl. implied directories) to a VM's osbash
    home directory
    """

    key_path = get_osbash_private_key()

    for src_path in args:
        target_path = hf.strip_top_dir(conf.top_dir, src_path)

        target_dir = os.path.dirname(target_path)
        if not target_dir:
            target_dir = '.'

        vm_ssh(vm_name, "mkdir", "-p", target_dir)

        target_port = str(conf.vm[vm_name].ssh_port)

        try:
            full_target = "{}@{}:{}".format(conf.vm_shell_user,
                                            conf.vm[vm_name].ssh_ip,
                                            target_path)
            logger.debug("Copying from\n\t%s\n\tto\n\t%s (port: %s)",
                         src_path, full_target, target_port)
            # To avoid getting stuck on broken ssh connection, disable
            # connection sharing (ControlPath) and use a timeout when
            # connecting.
            subprocess.check_output(["scp", "-q", "-r",
                                     "-i", key_path,
                                     "-o", "UserKnownHostsFile=/dev/null",
                                     "-o", "StrictHostKeyChecking=no",
                                     "-o", "ConnectTimeout=10",
                                     "-o", "ControlPath=none",
                                     "-P", target_port,
                                     src_path, full_target])
        except subprocess.CalledProcessError as err:
            logger.error("Copying from\n\t%s\n\tto\n\t%s",
                         src_path, full_target)
            logger.error("\trc=%s: %s", err.returncode, err.output)
            sys.exit(1)
Ejemplo n.º 4
0
def wbatch_path_to_windows(full_path):
    rel_path = hf.strip_top_dir(conf.top_dir, full_path)

    # Convert path to backslash-type as expected by Windows batch files
    rel_path = ntpath.normpath(rel_path)
    return rel_path
def wbatch_path_to_windows(full_path):
    rel_path = hf.strip_top_dir(conf.top_dir, full_path)

    # Convert path to backslash-type as expected by Windows batch files
    rel_path = ntpath.normpath(rel_path)
    return rel_path