From patchwork Wed Oct 7 17:54:16 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 52319 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n97I5tBB015201 for ; Wed, 7 Oct 2009 18:05:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755165AbZJGR6N (ORCPT ); Wed, 7 Oct 2009 13:58:13 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756728AbZJGR6M (ORCPT ); Wed, 7 Oct 2009 13:58:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34421 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755036AbZJGR6K (ORCPT ); Wed, 7 Oct 2009 13:58:10 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n97HvhZQ013948; Wed, 7 Oct 2009 13:57:43 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n97HvgMI028890; Wed, 7 Oct 2009 13:57:43 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n97Hve84014834; Wed, 7 Oct 2009 13:57:41 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 1/7] KVM test: migration test: move the bulk of the code to a utility function Date: Wed, 7 Oct 2009 19:54:16 +0200 Message-Id: <1254938062-15286-1-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/client/tests/kvm/kvm_test_utils.py b/client/tests/kvm/kvm_test_utils.py index 601b350..096a056 100644 --- a/client/tests/kvm/kvm_test_utils.py +++ b/client/tests/kvm/kvm_test_utils.py @@ -59,3 +59,75 @@ def wait_for_login(vm, nic_index=0, timeout=240): raise error.TestFail("Could not log into guest '%s'" % vm.name) logging.info("Logged in") return session + + +def migrate(vm, env=None): + """ + Migrate a VM locally and re-register it in the environment. + + @param vm: The VM to migrate. + @param env: The environment dictionary. If omitted, the migrated VM will + not be registered. + @return: The post-migration VM. + """ + # Helper functions + def mig_finished(): + s, o = vm.send_monitor_cmd("info migrate") + return s == 0 and not "Migration status: active" in o + + def mig_succeeded(): + s, o = vm.send_monitor_cmd("info migrate") + return s == 0 and "Migration status: completed" in o + + def mig_failed(): + s, o = vm.send_monitor_cmd("info migrate") + return s == 0 and "Migration status: failed" in o + + # See if migration is supported + s, o = vm.send_monitor_cmd("help info") + if not "info migrate" in o: + raise error.TestError("Migration is not supported") + + # Clone the source VM and ask the clone to wait for incoming migration + dest_vm = vm.clone() + dest_vm.create(for_migration=True) + + try: + # Define the migration command + cmd = "migrate -d tcp:localhost:%d" % dest_vm.migration_port + logging.debug("Migrating with command: %s" % cmd) + + # Migrate + s, o = vm.send_monitor_cmd(cmd) + if s: + logging.error("Migration command failed (command: %r, output: %r)" + % (cmd, o)) + raise error.TestFail("Migration command failed") + + # Wait for migration to finish + if not kvm_utils.wait_for(mig_finished, 90, 2, 2, + "Waiting for migration to finish..."): + raise error.TestFail("Timeout elapsed while waiting for migration " + "to finish") + + # Report migration status + if mig_succeeded(): + logging.info("Migration finished successfully") + elif mig_failed(): + raise error.TestFail("Migration failed") + else: + raise error.TestFail("Migration ended with unknown status") + + # Kill the source VM + vm.destroy(gracefully=False) + + # Replace the source VM with the new cloned VM + if env is not None: + kvm_utils.env_register_vm(env, vm.name, dest_vm) + + # Return the new cloned VM + return dest_vm + + except: + dest_vm.destroy() + raise diff --git a/client/tests/kvm/tests/migration.py b/client/tests/kvm/tests/migration.py index 2bbf17b..4b13b5d 100644 --- a/client/tests/kvm/tests/migration.py +++ b/client/tests/kvm/tests/migration.py @@ -21,79 +21,21 @@ def run_migration(test, params, env): """ vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) - # See if migration is supported - s, o = vm.send_monitor_cmd("help info") - if not "info migrate" in o: - raise error.TestError("Migration is not supported") - # 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() - # Clone the main VM and ask it to wait for incoming migration - dest_vm = vm.clone() - dest_vm.create(for_migration=True) - - try: - # Define the migration command - cmd = "migrate -d tcp:localhost:%d" % dest_vm.migration_port - logging.debug("Migration command: %s" % cmd) - - # Migrate - s, o = vm.send_monitor_cmd(cmd) - if s: - logging.error("Migration command failed (command: %r, output: %r)" - % (cmd, o)) - raise error.TestFail("Migration command failed") - - # Define some helper functions - def mig_finished(): - s, o = vm.send_monitor_cmd("info migrate") - return s == 0 and not "Migration status: active" in o - - def mig_succeeded(): - s, o = vm.send_monitor_cmd("info migrate") - return s == 0 and "Migration status: completed" in o - - def mig_failed(): - s, o = vm.send_monitor_cmd("info migrate") - return s == 0 and "Migration status: failed" in o - - # Wait for migration to finish - if not kvm_utils.wait_for(mig_finished, 90, 2, 2, - "Waiting for migration to finish..."): - raise error.TestFail("Timeout elapsed while waiting for migration " - "to finish") - - # Report migration status - if mig_succeeded(): - logging.info("Migration finished successfully") - elif mig_failed(): - raise error.TestFail("Migration failed") - else: - raise error.TestFail("Migration ended with unknown status") - - # Kill the source VM - vm.destroy(gracefully=False) - - # Replace the source VM with the new cloned VM - kvm_utils.env_register_vm(env, params.get("main_vm"), dest_vm) - - except: - dest_vm.destroy(gracefully=False) - raise + # Migrate the VM + dest_vm = kvm_test_utils.migrate(vm, env) # 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()