[KVM-AUTOTEST PATCH 3/6] KVM test: migration: rely on background process instead of timing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



1. Run a process in the background and make sure it keeps running after
migration (similarly to guest_s4).
2. When logging in after migration allow the procedure to take up to 30s
instead of only 10s.  We can afford this because if the guest reboots during
those 30s the background process will not keep running.

Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx>
---
 client/tests/kvm/kvm_tests.cfg.sample              |    6 ++
 client/tests/kvm/tests/migration.py                |   84 +++++++++++++------
 client/tests/kvm/tests/timedrift_with_migration.py |    2 +-
 3 files changed, 64 insertions(+), 28 deletions(-)

diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm/kvm_tests.cfg.sample
index 573206c..bcc31bb 100644
--- a/client/tests/kvm/kvm_tests.cfg.sample
+++ b/client/tests/kvm/kvm_tests.cfg.sample
@@ -77,6 +77,9 @@ variants:
     - migrate:      install setup
         type = migration
         migration_test_command = help
+        migration_bg_command = "cd /tmp; nohup tcpdump -q -t ip host localhost"
+        migration_bg_check_command = pgrep tcpdump
+        migration_bg_kill_command = pkill tcpdump
         kill_vm_on_error = yes
         iterations = 2
         used_mem = 1024
@@ -499,6 +502,9 @@ variants:
 
         migrate:
             migration_test_command = ver && vol
+            migration_bg_command = start ping -t localhost
+            migration_bg_check_command = tasklist | find /I "ping.exe"
+            migration_bg_kill_command = taskkill /IM ping.exe /F
         stress_boot:
             alive_test_cmd = systeminfo
         timedrift:
diff --git a/client/tests/kvm/tests/migration.py b/client/tests/kvm/tests/migration.py
index 4b13b5d..7b80e51 100644
--- a/client/tests/kvm/tests/migration.py
+++ b/client/tests/kvm/tests/migration.py
@@ -1,4 +1,4 @@
-import logging
+import logging, time
 from autotest_lib.client.common_lib import error
 import kvm_subprocess, kvm_test_utils, kvm_utils
 
@@ -20,33 +20,63 @@ def run_migration(test, params, env):
     @param env: Dictionary with the test environment.
     """
     vm = kvm_test_utils.get_living_vm(env, params.get("main_vm"))
-
-    # Log into guest and get the output of migration_test_command
     session = kvm_test_utils.wait_for_login(vm)
-    migration_test_command = params.get("migration_test_command")
-    reference_output = session.get_command_output(migration_test_command)
-    session.close()
 
-    # Migrate the VM
-    dest_vm = kvm_test_utils.migrate(vm, env)
+    # Get the output of migration_test_command
+    test_command = params.get("migration_test_command")
+    reference_output = session.get_command_output(test_command)
 
-    # Log into guest and get the output of migration_test_command
-    logging.info("Logging into guest after migration...")
-    session = dest_vm.remote_login()
-    if not session:
-        raise error.TestFail("Could not log into guest after migration")
-    logging.info("Logged in after migration")
-    output = session.get_command_output(migration_test_command)
-    session.close()
+    # Start some process in the background (and leave the session open)
+    background_command = params.get("migration_bg_command", "")
+    session.sendline(background_command)
+    time.sleep(5)
+
+    # Start another session with the guest and make sure the background
+    # process is running
+    session2 = kvm_test_utils.wait_for_login(vm)
+
+    try:
+        check_command = params.get("migration_bg_check_command", "")
+        if session2.get_command_status(check_command, timeout=30) != 0:
+            raise error.TestError("Could not start background process '%s'" %
+                                  background_command)
+        session2.close()
+
+        # Migrate the VM
+        dest_vm = kvm_test_utils.migrate(vm, env)
 
-    # Compare output to reference output
-    if output != reference_output:
-        logging.info("Command output before migration differs from command "
-                     "output after migration")
-        logging.info("Command: %s" % params.get("migration_test_command"))
-        logging.info("Output before:" +
-                     kvm_utils.format_str_for_message(reference_output))
-        logging.info("Output after:" +
-                     kvm_utils.format_str_for_message(output))
-        raise error.TestFail("Command produced different output before and "
-                             "after migration")
+        # Log into the guest again
+        logging.info("Logging into guest after migration...")
+        session2 = kvm_utils.wait_for(dest_vm.remote_login, 30, 0, 2)
+        if not session2:
+            raise error.TestFail("Could not log into guest after migration")
+        logging.info("Logged in after migration")
+
+        # Make sure the background process is still running
+        if session2.get_command_status(check_command, timeout=30) != 0:
+            raise error.TestFail("Could not find running background process "
+                                 "after migration: '%s'" % background_command)
+
+        # Get the output of migration_test_command
+        output = session2.get_command_output(test_command)
+
+        # Compare output to reference output
+        if output != reference_output:
+            logging.info("Command output before migration differs from "
+                         "command output after migration")
+            logging.info("Command: %s" % test_command)
+            logging.info("Output before:" +
+                         kvm_utils.format_str_for_message(reference_output))
+            logging.info("Output after:" +
+                         kvm_utils.format_str_for_message(output))
+            raise error.TestFail("Command '%s' produced different output "
+                                 "before and after migration" % test_command)
+
+    finally:
+        # Kill the background process
+        if session2.is_alive():
+            session2.get_command_output(params.get("migration_bg_kill_command",
+                                                   ""))
+
+    session2.close()
+    session.close()
diff --git a/client/tests/kvm/tests/timedrift_with_migration.py b/client/tests/kvm/tests/timedrift_with_migration.py
index af02f97..99d645a 100644
--- a/client/tests/kvm/tests/timedrift_with_migration.py
+++ b/client/tests/kvm/tests/timedrift_with_migration.py
@@ -49,7 +49,7 @@ def run_timedrift_with_migration(test, params, env):
             vm = kvm_test_utils.migrate(vm, env)
             # Log in
             logging.info("Logging in after migration...")
-            session = vm.remote_login()
+            session = kvm_utils.wait_for(vm.remote_login, 30, 0, 2)
             if not session:
                 raise error.TestFail("Could not log in after migration")
             logging.info("Logged in after migration")
-- 
1.5.4.1

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux