As we use a dedicated thread to run the file transfer in the
background. The file transfer thread may run after the migration
finished, then we may get error because the vm object we pass to
BackgroundTest have been destroyed.

This patch make the migration_with_file_transfer safer by:
- get the params before running tests in parallel
- run kvm_utils.scp_to_remote() in the background which does not
require a vm object instead of vm.copy_files_to()

Signed-off-by: Jason Wang <[email protected]>
---
 .../kvm/tests/migration_with_file_transfer.py      |   42 ++++++++++++++------
 1 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/client/tests/kvm/tests/migration_with_file_transfer.py 
b/client/tests/kvm/tests/migration_with_file_transfer.py
index 8a316bf..4be70cd 100644
--- a/client/tests/kvm/tests/migration_with_file_transfer.py
+++ b/client/tests/kvm/tests/migration_with_file_transfer.py
@@ -1,4 +1,4 @@
-import logging, time
+import logging, time, os
 from autotest_lib.client.common_lib import utils, error
 import kvm_subprocess, kvm_test_utils, kvm_utils
 
@@ -19,12 +19,12 @@ def run_migration_with_file_transfer(test, params, env):
     @param env: Dictionary with the test environment.
     """
 
-    def transfer_test(vm, host_path, guest_path, timeout=120):
-        """
-        vm.copy_files_to does not raise exception, so we need a wrapper
-        in order to make it to be used by BackgroundTest.
-        """
-        if not vm.copy_files_to(host_path, guest_path, timeout=timeout):
+    def transfer_test(address, client, username, password, port, local_path,
+                      remote_path, log_filename, timeout):
+        # kvm_utils.copy_files_to does not raise exception, so we need a 
wrapper
+        # in order to make it to be used by BackgroundTest.
+        if not kvm_utils.copy_files_to(address, client, username, password,
+                      port, local_path, remote_path, log_filename, timeout):
             raise error.TestError("Fail to do the file transfer!")
 
     vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
@@ -34,26 +34,42 @@ def run_migration_with_file_transfer(test, params, env):
     mig_timeout = float(params.get("mig_timeout", "3600"))
     mig_protocol = params.get("migration_protocol", "tcp")
 
+    # params of transfer test
+    username = vm.params.get("username", "")
+    password = vm.params.get("password", "")
+    client = vm.params.get("file_transfer_client")
+    address = vm.get_address(0)
+    port = vm.get_port(int(params.get("file_transfer_port")))
+    log_filename = ("migration-transfer-%s-to-%s-%s.log" %
+                    (vm.name, address,
+                     kvm_utils.generate_random_string(4)))
     guest_path = params.get("guest_path", "/tmp")
     file_size = params.get("file_size", "1000")
     transfer_timeout = int(params.get("transfer_timeout", "240"))
+
     bg = None
 
     try:
         utils.run("dd if=/dev/zero of=/tmp/file bs=1M count=%s" % file_size)
 
-        # Transfer file from host to guest
+        # Transfer file from host to guest in the backgroud
         bg = kvm_test_utils.BackgroundTest(transfer_test,
-                                           (vm, "/tmp/file", guest_path,
-                                            transfer_timeout))
+                                           (address, client, username, 
password,
+                                            port, "/tmp/file", guest_path,
+                                            log_filename, transfer_timeout))
         bg.start()
 
         while bg.is_alive():
-            logging.info("File transfer is not ended, start a round of 
migration ...")
+            logging.info("File transfer is not ended, start a round of"
+                         "migration ...")
+
             # Migrate the VM
-            dest_vm = kvm_test_utils.migrate(vm, env, mig_timeout, 
mig_protocol, False)
+            dest_vm = kvm_test_utils.migrate(vm, env, mig_timeout,
+                                             mig_protocol, False)
+
             vm = dest_vm
     finally:
         if bg: bg.join()
         session.close()
-        utils.run("rm -rf /tmp/zero")
+        if os.path.isfile("/tmp/zero"):
+            os.remove("/tmp/zero")

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to