On Tue, 2010-12-14 at 19:47 +0800, Jason Wang wrote: > Move the file transfer helpers to kvm_utils.py and make it easier to be called > by BackgroundTest.
Ok Jason, patchsets applied: http://autotest.kernel.org/changeset/4995 http://autotest.kernel.org/changeset/4996 http://autotest.kernel.org/changeset/4997 Michael, it's done, so you might want to rebase your patches for the BackgroundTest! Cheers, Lucas > Signed-off-by: Jason Wang <[email protected]> > --- > client/tests/kvm/kvm_utils.py | 68 > ++++++++++++++++++++++++++++++++++++++++- > client/tests/kvm/kvm_vm.py | 43 +++++++------------------- > 2 files changed, 78 insertions(+), 33 deletions(-) > > diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py > index 0d380b6..7a88114 100644 > --- a/client/tests/kvm/kvm_utils.py > +++ b/client/tests/kvm/kvm_utils.py > @@ -5,7 +5,7 @@ KVM test utility functions. > """ > > import time, string, random, socket, os, signal, re, logging, commands, > cPickle > -import fcntl, shelve, ConfigParser > +import fcntl, shelve, ConfigParser, rss_file_transfer > from autotest_lib.client.bin import utils, os_dep > from autotest_lib.client.common_lib import error, logging_config > import kvm_subprocess > @@ -638,10 +638,74 @@ def remote_scp(command, password, log_filename=None, > transfer_timeout=600, > session.close() > > > +def copy_files_to(address, client, username, password, port, local_path, > + remote_path, log_filename=None, timeout=600): > + """ > + Decide the transfer cleint and copy file to a remote host (guest). > + > + @param client: Type of transfer client > + @param username: Username (if required) > + @param password: Password (if requried) > + @param local_path: Path on the local machine where we are copying from > + @param remote_path: Path on the remote machine where we are copying to > + @param address: Address of remote host(guest) > + @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. > + """ > + > + if not address or not port: > + logging.debug("IP address or port unavailable") > + return None > + > + if client == "scp": > + return scp_to_remote(address, port, username, password, local_path, > + remote_path, log_filename, timeout) > + elif client == "rss": > + c = rss_file_transfer.FileUploadClient(address, port) > + c.upload(local_path, remote_path, timeout) > + c.close() > + return True > + > + > +def copy_files_from(address, client, username, password, port, local_path, > + remote_path, log_filename=None, timeout=600): > + """ > + Decide the transfer cleint and copy file from a remote host (guest). > + > + @param client: Type of transfer client > + @param username: Username (if required) > + @param password: Password (if requried) > + @param local_path: Path on the local machine where we are copying from > + @param remote_path: Path on the remote machine where we are copying to > + @param address: Address of remote host(guest) > + @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. > + """ > + > + if not address or not port: > + logging.debug("IP address or port unavailable") > + return None > + > + if client == "scp": > + return scp_from_remote(address, port, username, password, > remote_path, > + local_path, log_filename, timeout) > + elif client == "rss": > + c = rss_file_transfer.FileDownloadClient(address, port) > + c.download(remote_path, local_path, timeout) > + c.close() > + return True > + > + > def scp_to_remote(host, port, username, password, local_path, remote_path, > log_filename=None, timeout=600): > """ > - Copy files to a remote host (guest). > + Copy files to a remote host (guest) through scp. > > @param host: Hostname or IP address > @param username: Username (if required) > diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py > index 416b827..6550676 100755 > --- a/client/tests/kvm/kvm_vm.py > +++ b/client/tests/kvm/kvm_vm.py > @@ -1071,7 +1071,7 @@ class VM: > > def copy_files_to(self, local_path, remote_path, nic_index=0, > timeout=600): > """ > - Transfer files to the guest. > + Transfer files to the remote host(guest). > > @param local_path: Host path > @param remote_path: Guest path > @@ -1085,21 +1085,12 @@ class VM: > address = self.get_address(nic_index) > port = self.get_port(int(self.params.get("file_transfer_port"))) > > - if not address or not port: > - logging.debug("IP address or port unavailable") > - return None > - > - if client == "scp": > - log_filename = ("scp-%s-%s.log" % > - (self.name, kvm_utils.generate_random_string(4))) > - return kvm_utils.scp_to_remote(address, port, username, password, > - local_path, remote_path, > - log_filename, timeout) > - elif client == "rss": > - c = rss_file_transfer.FileUploadClient(address, port) > - c.upload(local_path, remote_path, timeout) > - c.close() > - return True > + log_filename = ("transfer-%s-to-%s-%s.log" % > + (self.name, address, > + kvm_utils.generate_random_string(4))) > + return kvm_utils.copy_files_to(address, client, username, password, > + port, local_path, remote_path, > + log_filename, timeout) > > > def copy_files_from(self, remote_path, local_path, nic_index=0, > timeout=600): > @@ -1118,21 +1109,11 @@ class VM: > address = self.get_address(nic_index) > port = self.get_port(int(self.params.get("file_transfer_port"))) > > - if not address or not port: > - logging.debug("IP address or port unavailable") > - return None > - > - if client == "scp": > - log_filename = ("scp-%s-%s.log" % > - (self.name, kvm_utils.generate_random_string(4))) > - return kvm_utils.scp_from_remote(address, port, username, > password, > - remote_path, local_path, > - log_filename, timeout) > - elif client == "rss": > - c = rss_file_transfer.FileDownloadClient(address, port) > - c.download(remote_path, local_path, timeout) > - c.close() > - return True > + log_filename = ("transfer-%s-from-%s-%s.log" % > + (self.name, address, > + kvm_utils.generate_random_string(4))) > + return kvm_utils.copy_files_from(address, client, username, password, > + port, local_path, remote_path, log_filename, timeout) > > > def serial_login(self, timeout=10): > _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
