All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Goldish <mgoldish@redhat.com>
To: autotest@test.kernel.org, kvm@vger.kernel.org
Subject: [KVM-AUTOTEST PATCH 14/17] KVM test: simplify migration_with_reboot and migration_with_file_transfer
Date: Mon,  3 Jan 2011 20:27:15 +0200	[thread overview]
Message-ID: <1294079238-21239-14-git-send-email-mgoldish@redhat.com> (raw)
In-Reply-To: <1294079238-21239-1-git-send-email-mgoldish@redhat.com>

Now that migration can be performed without switching VMs (but rather by
switching states) these tests can be greatly simplified.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
 .../kvm/tests/migration_with_file_transfer.py      |   53 +++++++-------------
 client/tests/kvm/tests/migration_with_reboot.py    |   54 ++-----------------
 2 files changed, 24 insertions(+), 83 deletions(-)

diff --git a/client/tests/kvm/tests/migration_with_file_transfer.py b/client/tests/kvm/tests/migration_with_file_transfer.py
index f641451..27c1fe1 100644
--- a/client/tests/kvm/tests/migration_with_file_transfer.py
+++ b/client/tests/kvm/tests/migration_with_file_transfer.py
@@ -21,21 +21,12 @@ def run_migration_with_file_transfer(test, params, env):
     """
     vm = env.get_vm(params["main_vm"])
     vm.verify_alive()
-    timeout = int(params.get("login_timeout", 360))
-    session = vm.wait_for_login(timeout=timeout)
+    login_timeout = int(params.get("login_timeout", 360))
+    session = vm.wait_for_login(timeout=login_timeout)
 
     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)))
     host_path = "/tmp/file-%s" % kvm_utils.generate_random_string(6)
     host_path_returned = "%s-returned" % host_path
     guest_path = params.get("guest_path", "/tmp/file")
@@ -46,33 +37,26 @@ def run_migration_with_file_transfer(test, params, env):
         utils.run("dd if=/dev/urandom of=%s bs=1M count=%s" % (host_path,
                                                                file_size))
 
+        def run_and_migrate(bg):
+            bg.start()
+            try:
+                while bg.is_alive():
+                    logging.info("File transfer not ended, starting a round of "
+                                 "migration...")
+                    vm.migrate(mig_timeout, mig_protocol)
+            finally:
+                bg.join()
+
         logging.info("Transferring file from host to guest")
-        bg = kvm_utils.Thread(kvm_utils.copy_files_to,
-                              (address, client, username, password, port,
-                               host_path, guest_path, log_filename,
-                               transfer_timeout))
-        bg.start()
-        try:
-            while bg.is_alive():
-                logging.info("File transfer not ended, starting a round of "
-                             "migration...")
-                vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol)
-        finally:
-            bg.join()
+        bg = kvm_utils.Thread(vm.copy_files_to,
+                              (host_path, guest_path, 0, transfer_timeout))
+        run_and_migrate(bg)
 
         logging.info("Transferring file back from guest to host")
-        bg = kvm_utils.Thread(kvm_utils.copy_files_from,
-                              (address, client, username, password, port,
-                               host_path_returned, guest_path, log_filename,
+        bg = kvm_utils.Thread(vm.copy_files_from,
+                              (guest_path, host_path_returned, 0,
                                transfer_timeout))
-        bg.start()
-        try:
-            while bg.is_alive():
-                logging.info("File transfer not ended, starting a round of "
-                             "migration...")
-                vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol)
-        finally:
-            bg.join()
+        run_and_migrate(bg)
 
         # Make sure the returned file is indentical to the original one
         orig_hash = client_utils.hash_file(host_path)
@@ -81,7 +65,6 @@ def run_migration_with_file_transfer(test, params, env):
             raise error.TestFail("Returned file hash (%s) differs from "
                                  "original one (%s)" % (returned_hash,
                                                         orig_hash))
-
     finally:
         session.close()
         if os.path.isfile(host_path):
diff --git a/client/tests/kvm/tests/migration_with_reboot.py b/client/tests/kvm/tests/migration_with_reboot.py
index c96a4d7..a365239 100644
--- a/client/tests/kvm/tests/migration_with_reboot.py
+++ b/client/tests/kvm/tests/migration_with_reboot.py
@@ -19,65 +19,23 @@ def run_migration_with_reboot(test, params, env):
     @param params: Dictionary with test parameters.
     @param env: Dictionary with the test environment.
     """
-    def reboot_test(client, session, address, reboot_command, port, username,
-                    password, prompt, linesep, log_filename, timeout):
-        """
-        A version of reboot test which is safe to be called in the background as
-        it doesn't need a VM object.
-        """
-        # Send a reboot command to the guest's shell
-        session.sendline(reboot_command)
-        logging.info("Reboot command sent. Waiting for guest to go down...")
-
-        # Wait for the session to become unresponsive and close it
-        if not kvm_utils.wait_for(lambda: not session.is_responsive(timeout=30),
-                                  120, 0, 1):
-            raise error.TestFail("Guest refuses to go down")
-        session.close()
-
-        # Try logging into the guest until timeout expires
-        logging.info("Guest is down. Waiting for it to go up again, timeout "
-                     "%ds", timeout)
-        session = kvm_utils.wait_for_login(client, address, port, username,
-                                           password, prompt, linesep,
-                                           log_filename, timeout)
-        logging.info("Guest is up again")
-        session.close()
-
     vm = env.get_vm(params["main_vm"])
     vm.verify_alive()
-    timeout = int(params.get("login_timeout", 360))
-    session = vm.wait_for_login(timeout=timeout)
-
-    # params of reboot
-    username = vm.params.get("username", "")
-    password = vm.params.get("password", "")
-    prompt = vm.params.get("shell_prompt", "[\#\$]")
-    linesep = eval("'%s'" % vm.params.get("shell_linesep", r"\n"))
-    client = vm.params.get("shell_client")
-    address = vm.get_address(0)
-    port = vm.get_port(int(params.get("shell_port")))
-    log_filename = ("migration-reboot-%s-%s.log" %
-                    (vm.name, kvm_utils.generate_random_string(4)))
-    reboot_command = vm.params.get("reboot_command")
+    login_timeout = int(params.get("login_timeout", 360))
+    session = vm.wait_for_login(timeout=login_timeout)
 
     mig_timeout = float(params.get("mig_timeout", "3600"))
     mig_protocol = params.get("migration_protocol", "tcp")
-    mig_cancel = bool(params.get("mig_cancel"))
+    mig_cancel_delay = int(params.get("mig_cancel") == "yes") * 2
 
     try:
         # Reboot the VM in the background
-        bg = kvm_utils.Thread(reboot_test, (client, session, address,
-                                            reboot_command, port, username,
-                                            password, prompt, linesep,
-                                            log_filename, timeout))
+        bg = kvm_utils.Thread(kvm_test_utils.reboot, (vm, session))
         bg.start()
-
         try:
             while bg.is_alive():
-                vm = kvm_test_utils.migrate(vm, env, mig_timeout, mig_protocol)
+                vm.migrate(mig_timeout, mig_protocol, mig_cancel_delay)
         finally:
-            bg.join()
-
+            session = bg.join()
     finally:
         session.close()
-- 
1.7.3.4

  parent reply	other threads:[~2011-01-03 18:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-03 18:27 [KVM-AUTOTEST PATCH 01/17] KVM test: introduce exception classes for _remote_login() and _remote_scp() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 02/17] KVM test: kvm_utils.py: reorder remote_login(), remote_scp(), copy_files_to(), etc Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 03/17] KVM test: use the new LoginError and SCPError exceptions Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 04/17] KVM test: add VM.wait_for_login() and kvm_utils.wait_for_login() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 05/17] KVM test: use the new wait_for_login() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 06/17] KVM test: rename VM.remote_login() to VM.login() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 07/17] KVM test: introduce VM exceptions Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 08/17] KVM test: let kvm_vm.create_image() raise a CmdError if qemu-img fails Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 09/17] KVM test: use the new VM exceptions Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 10/17] KVM test: add VM.verify_alive() and Monitor.verify_responsive() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 11/17] KVM test: use VM.verify_alive() instead of kvm_test_utils.get_living_vm() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 12/17] KVM test: kvm_preprocessing.py: simplify handling of params['migration_mode'] Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 13/17] KVM test: make migrate() a VM method Michael Goldish
2011-01-03 18:27 ` Michael Goldish [this message]
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 15/17] KVM test: use VM.migrate() instead of kvm_test_utils.migrate() Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 16/17] KVM test: reorder kvm_utils.copy_files_from() path parameters Michael Goldish
2011-01-03 18:27 ` [KVM-AUTOTEST PATCH 17/17] KVM test: rename path parameters in kvm_vm.copy_files_*() Michael Goldish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1294079238-21239-14-git-send-email-mgoldish@redhat.com \
    --to=mgoldish@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.