public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Lucas Meneghel Rodrigues <lmr@redhat.com>
To: autotest@test.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 4/5] KVM test: Modifications on the migrate utility function
Date: Mon, 20 Dec 2010 11:57:33 -0500	[thread overview]
Message-ID: <1292864254-6782-4-git-send-email-lmr@redhat.com> (raw)
In-Reply-To: <1292864254-6782-1-git-send-email-lmr@redhat.com>

In order to accomodate multi-host migration, make migrate
accept 2 additional parameters, dest_host and mig_port.
Also, handle properly the case where we are doing migration
inside the same host.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 client/tests/kvm/kvm_test_utils.py |   50 +++++++++++++++++++++++------------
 1 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py
index d0f2e6c..2a3a062 100644
--- a/client/tests/kvm/kvm_test_utils.py
+++ b/client/tests/kvm/kvm_test_utils.py
@@ -134,7 +134,7 @@ def reboot(vm, session, method="shell", sleep_before_reset=10, nic_index=0,
 
 def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
             mig_cancel=False, offline=False, stable_check=False,
-            clean=False, save_path=None):
+            clean=False, save_path=None, dest_host='localhost', mig_port=None):
     """
     Migrate a VM locally and re-register it in the environment.
 
@@ -144,7 +144,10 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
     @param mig_timeout: timeout value for migration.
     @param mig_protocol: migration protocol
     @param mig_cancel: Test migrate_cancel or not when protocol is tcp.
-    @return: The post-migration VM.
+    @param dest_host: Destination host (defaults to 'localhost').
+    @param mig_port: Port that will be used for migration.
+    @return: The post-migration VM, in case of same host migration, True in
+            case of multi-host migration.
     """
     def mig_finished():
         o = vm.monitor.info("migrate")
@@ -182,18 +185,25 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
             raise error.TestFail("Timeout expired while waiting for migration "
                                  "to finish")
 
-    dest_vm = vm.clone()
-    if stable_check:
+    if dest_host == 'localhost':
+        dest_vm = vm.clone()
+
+    if (dest_host == 'localhost') and stable_check:
         # Pause the dest vm after creation
         dest_vm.params['extra_params'] = (dest_vm.params.get('extra_params','')
                                           + ' -S')
 
-    if not dest_vm.create(migration_mode=mig_protocol, mac_source=vm):
-        raise error.TestError("Could not create dest VM")
+    if dest_host == 'localhost':
+        if not dest_vm.create(migration_mode=mig_protocol, mac_source=vm):
+            raise error.TestError("Could not create dest VM")
+
     try:
         try:
             if mig_protocol == "tcp":
-                uri = "tcp:localhost:%d" % dest_vm.migration_port
+                if dest_host == 'localhost':
+                    uri = "tcp:localhost:%d" % dest_vm.migration_port
+                else:
+                    uri = 'tcp:%s:%d' % (dest_host, mig_port)
             elif mig_protocol == "unix":
                 uri = "unix:%s" % dest_vm.migration_file
             elif mig_protocol == "exec":
@@ -212,11 +222,12 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
                     raise error.TestFail("Failed to cancel migration")
                 if offline:
                     vm.monitor.cmd("cont")
-                dest_vm.destroy(gracefully=False)
+                if dest_host == 'localhost':
+                    dest_vm.destroy(gracefully=False)
                 return vm
             else:
                 wait_for_migration()
-                if stable_check:
+                if (dest_host == 'localhost') and stable_check:
                     save_path = None or "/tmp"
                     save1 = os.path.join(save_path, "src")
                     save2 = os.path.join(save_path, "dst")
@@ -231,14 +242,15 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
                         raise error.TestFail("Mismatch of VM state before "
                                              "and after migration")
 
-                if offline:
+                if (dest_host == 'localhost') and offline:
                     dest_vm.monitor.cmd("cont")
         except:
-            dest_vm.destroy()
+            if dest_host == 'localhost':
+                dest_vm.destroy()
             raise
 
     finally:
-        if stable_check and clean:
+        if (dest_host == 'localhost') and stable_check and clean:
             logging.debug("Cleaning the state files")
             if os.path.isfile(save1):
                 os.remove(save1)
@@ -253,19 +265,23 @@ def migrate(vm, env=None, mig_timeout=3600, mig_protocol="tcp",
     else:
         raise error.TestFail("Migration ended with unknown status")
 
-    if "paused" in dest_vm.monitor.info("status"):
-        logging.debug("Destination VM is paused, resuming it...")
-        dest_vm.monitor.cmd("cont")
+    if dest_host == 'localhost':
+        if "paused" in dest_vm.monitor.info("status"):
+            logging.debug("Destination VM is paused, resuming it...")
+            dest_vm.monitor.cmd("cont")
 
     # Kill the source VM
     vm.destroy(gracefully=False)
 
     # Replace the source VM with the new cloned VM
-    if env is not None:
+    if (dest_host == 'localhost') and (env is not None):
         kvm_utils.env_register_vm(env, vm.name, dest_vm)
 
     # Return the new cloned VM
-    return dest_vm
+    if dest_host == 'localhost':
+        return dest_vm
+    else:
+        return vm
 
 
 def stop_windows_service(session, service, timeout=120):
-- 
1.7.3.4

  parent reply	other threads:[~2010-12-20 16:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-20 16:57 [PATCH 1/5] KVM test: Include the preprocessing param migration_mode Lucas Meneghel Rodrigues
2010-12-20 16:57 ` [PATCH 2/5] KVM test: Introduce migration_multi_host test Lucas Meneghel Rodrigues
2010-12-20 16:57 ` [PATCH 3/5] KVM test: Add migration server control file Lucas Meneghel Rodrigues
2010-12-20 16:57 ` Lucas Meneghel Rodrigues [this message]
2010-12-20 16:57 ` [PATCH 5/5] KVM test: kvm_vm: Allow NIC MACs to be defined on config file Lucas Meneghel Rodrigues

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=1292864254-6782-4-git-send-email-lmr@redhat.com \
    --to=lmr@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox