This function will help test to scp file between two remote os. It can be two guest, one guest and one host or other conditions
Signed-off-by: Yiqiao Pu <[email protected]> --- client/tests/kvm/kvm_utils.py | 46 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 44 insertions(+), 2 deletions(-) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index de52b65..19a613d 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -701,6 +701,8 @@ def _remote_scp(session, password, transfer_timeout=600, login_timeout=10): timeout = login_timeout authentication_done = False + scp_type = len(password) + while True: try: match, text = session.read_until_last_line_matches( @@ -714,6 +716,18 @@ def _remote_scp(session, password, transfer_timeout=600, login_timeout=10): if password_prompt_count == 0: logging.debug("Got password prompt; sending '%s'", password) session.sendline(password) + logging.debug("Got password prompt; sending '%s'" % + password[password_prompt_count]) + session.sendline(password[password_prompt_count]) + password_prompt_count += 1 + timeout = transfer_timeout + if scp_type == 1: + authentication_done = True + continue + elif password_prompt_count == 1 and scp_type == 2: + logging.debug("Got password prompt; sending '%s'" % + password[password_prompt_count]) + session.sendline(password[password_prompt_count]) password_prompt_count += 1 timeout = transfer_timeout authentication_done = True @@ -789,7 +803,10 @@ def scp_to_remote(host, port, username, password, local_path, remote_path, command = ("scp -v -o UserKnownHostsFile=/dev/null " "-o PreferredAuthentications=password -r -P %s %s %s@%s:%s" % (port, local_path, username, host, remote_path)) - remote_scp(command, password, log_filename, timeout) + password_list = [] + password_list.append(password) + return remote_scp(command, password_list, log_filename, timeout) + def scp_from_remote(host, port, username, password, remote_path, local_path, @@ -810,8 +827,33 @@ def scp_from_remote(host, port, username, password, remote_path, local_path, command = ("scp -v -o UserKnownHostsFile=/dev/null " "-o PreferredAuthentications=password -r -P %s %s@%s:%s %s" % (port, username, host, remote_path, local_path)) - remote_scp(command, password, log_filename, timeout) + password_list = [] + password_list.append(password) + remote_scp(command, password_list, log_filename, timeout) + +def scp_remote(src, dst, port, s_passwd, d_passwd, s_name, d_name, s_path, + d_path, log_filename=None, timeout=600): + """ + Copy files from a remote host (guest) to another remote host(guest). + + @param src/dst: Hostname or IP address of src and dst + @param s_name/d_name: Username (if required) + @param s_passwd/d_passwd: Password (if required) + @param s_path/d_path: Path on the remote machine where we are copying + from/to + @param log_filename: If specified, log all output to this file + @param timeout: The time duration (in seconds) to wait for the transfer + to complete. + @return: True on success and False on failure. + """ + command = ("scp -v -o UserKnownHostsFile=/dev/null -o " + "PreferredAuthentications=password -r -P %s %s@%s:%s %s@%s:%s" % + (port, s_name, src, s_path, d_name, dst, d_path)) + password_list = [] + password_list.append(s_passwd) + password_list.append(d_passwd) + return remote_scp(command, password_list, log_filename, timeout) def copy_files_to(address, client, username, password, port, local_path, remote_path, log_filename=None, verbose=False, timeout=600): -- 1.7.1 _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
