| OLD | NEW |
| 1 import logging, time, os | 1 import logging, time, os |
| 2 from autotest_lib.client.common_lib import error | 2 from autotest_lib.client.common_lib import error |
| 3 from autotest_lib.client.bin import utils | 3 from autotest_lib.client.bin import utils |
| 4 import kvm_utils | 4 from autotest_lib.client.virt import virt_utils |
| 5 |
| 5 | 6 |
| 6 def run_file_transfer(test, params, env): | 7 def run_file_transfer(test, params, env): |
| 7 """ | 8 """ |
| 8 Test ethrnet device function by ethtool | 9 Test ethrnet device function by ethtool |
| 9 | 10 |
| 10 1) Boot up a VM. | 11 1) Boot up a VM. |
| 11 2) Create a large file by dd on host. | 12 2) Create a large file by dd on host. |
| 12 3) Copy this file from host to guest. | 13 3) Copy this file from host to guest. |
| 13 4) Copy this file from guest to host. | 14 4) Copy this file from guest to host. |
| 14 5) Check if file transfers ended good. | 15 5) Check if file transfers ended good. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 27 transfer_timeout = int(params.get("transfer_timeout")) | 28 transfer_timeout = int(params.get("transfer_timeout")) |
| 28 transfer_type = params.get("transfer_type") | 29 transfer_type = params.get("transfer_type") |
| 29 tmp_dir = params.get("tmp_dir", "/tmp/") | 30 tmp_dir = params.get("tmp_dir", "/tmp/") |
| 30 clean_cmd = params.get("clean_cmd", "rm -f") | 31 clean_cmd = params.get("clean_cmd", "rm -f") |
| 31 filesize = int(params.get("filesize", 4000)) | 32 filesize = int(params.get("filesize", 4000)) |
| 32 count = int(filesize / 10) | 33 count = int(filesize / 10) |
| 33 if count == 0: | 34 if count == 0: |
| 34 count = 1 | 35 count = 1 |
| 35 | 36 |
| 36 host_path = os.path.join(dir_name, "tmp-%s" % | 37 host_path = os.path.join(dir_name, "tmp-%s" % |
| 37 kvm_utils.generate_random_string(8)) | 38 virt_utils.generate_random_string(8)) |
| 38 host_path2 = host_path + ".2" | 39 host_path2 = host_path + ".2" |
| 39 cmd = "dd if=/dev/zero of=%s bs=10M count=%d" % (host_path, count) | 40 cmd = "dd if=/dev/zero of=%s bs=10M count=%d" % (host_path, count) |
| 40 guest_path = (tmp_dir + "file_transfer-%s" % | 41 guest_path = (tmp_dir + "file_transfer-%s" % |
| 41 kvm_utils.generate_random_string(8)) | 42 virt_utils.generate_random_string(8)) |
| 42 | 43 |
| 43 try: | 44 try: |
| 44 logging.info("Creating %dMB file on host", filesize) | 45 logging.info("Creating %dMB file on host", filesize) |
| 45 utils.run(cmd) | 46 utils.run(cmd) |
| 46 | 47 |
| 47 if transfer_type == "remote": | 48 if transfer_type == "remote": |
| 48 logging.info("Transfering file host -> guest, timeout: %ss", | 49 logging.info("Transfering file host -> guest, timeout: %ss", |
| 49 transfer_timeout) | 50 transfer_timeout) |
| 50 t_begin = time.time() | 51 t_begin = time.time() |
| 51 vm.copy_files_to(host_path, guest_path, timeout=transfer_timeout) | 52 vm.copy_files_to(host_path, guest_path, timeout=transfer_timeout) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 74 finally: | 75 finally: |
| 75 logging.info('Cleaning temp file on guest') | 76 logging.info('Cleaning temp file on guest') |
| 76 session.cmd("rm -rf %s" % guest_path) | 77 session.cmd("rm -rf %s" % guest_path) |
| 77 logging.info('Cleaning temp files on host') | 78 logging.info('Cleaning temp files on host') |
| 78 try: | 79 try: |
| 79 os.remove(host_path) | 80 os.remove(host_path) |
| 80 os.remove(host_path2) | 81 os.remove(host_path2) |
| 81 except OSError: | 82 except OSError: |
| 82 pass | 83 pass |
| 83 session.close() | 84 session.close() |
| OLD | NEW |