From patchwork Wed Sep 9 18:12:06 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 46434 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 n89IFnHo019187 for ; Wed, 9 Sep 2009 18:15:50 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753982AbZIISPn (ORCPT ); Wed, 9 Sep 2009 14:15:43 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753974AbZIISPl (ORCPT ); Wed, 9 Sep 2009 14:15:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62862 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753965AbZIISPk (ORCPT ); Wed, 9 Sep 2009 14:15:40 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n89IFgMk018042; Wed, 9 Sep 2009 14:15:43 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n89IFfYN014423; Wed, 9 Sep 2009 14:15:42 -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 n89IFNFY012008; Wed, 9 Sep 2009 14:15:40 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [PATCH 13/19] KVM test: kvm_tests.py: save test code by using utilities in kvm_test_utils.py Date: Wed, 9 Sep 2009 21:12:06 +0300 Message-Id: <1252519932-30733-13-git-send-email-mgoldish@redhat.com> In-Reply-To: <1252519932-30733-12-git-send-email-mgoldish@redhat.com> References: <1252519932-30733-1-git-send-email-mgoldish@redhat.com> <1252519932-30733-2-git-send-email-mgoldish@redhat.com> <1252519932-30733-3-git-send-email-mgoldish@redhat.com> <1252519932-30733-4-git-send-email-mgoldish@redhat.com> <1252519932-30733-5-git-send-email-mgoldish@redhat.com> <1252519932-30733-6-git-send-email-mgoldish@redhat.com> <1252519932-30733-7-git-send-email-mgoldish@redhat.com> <1252519932-30733-8-git-send-email-mgoldish@redhat.com> <1252519932-30733-9-git-send-email-mgoldish@redhat.com> <1252519932-30733-10-git-send-email-mgoldish@redhat.com> <1252519932-30733-11-git-send-email-mgoldish@redhat.com> <1252519932-30733-12-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Michael Goldish --- client/tests/kvm/kvm_tests.py | 148 ++++++++--------------------------------- 1 files changed, 27 insertions(+), 121 deletions(-) diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py index 863b863..35666cf 100644 --- a/client/tests/kvm/kvm_tests.py +++ b/client/tests/kvm/kvm_tests.py @@ -1,6 +1,6 @@ import time, os, logging, re, commands from autotest_lib.client.common_lib import utils, error -import kvm_utils, kvm_subprocess, ppm_utils, scan_results +import kvm_utils, kvm_subprocess, ppm_utils, scan_results, kvm_test_utils """ KVM test definitions. @@ -21,21 +21,10 @@ def run_boot(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment. """ - vm = kvm_utils.env_get_vm(env, params.get("main_vm")) - if not vm: - raise error.TestError("VM object not found in environment") - if not vm.is_alive(): - raise error.TestError("VM seems to be dead; Test requires a living VM") - - logging.info("Waiting for guest to be up...") - - session = kvm_utils.wait_for(vm.remote_login, 240, 0, 2) - if not session: - raise error.TestFail("Could not log into guest") + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm) try: - logging.info("Logged in") - if params.get("reboot_method") == "shell": # Send a reboot command to the guest's shell session.sendline(vm.get_params().get("reboot_command")) @@ -81,21 +70,10 @@ def run_shutdown(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment """ - vm = kvm_utils.env_get_vm(env, params.get("main_vm")) - if not vm: - raise error.TestError("VM object not found in environment") - if not vm.is_alive(): - raise error.TestError("VM seems to be dead; Test requires a living VM") - - logging.info("Waiting for guest to be up...") - - session = kvm_utils.wait_for(vm.remote_login, 240, 0, 2) - if not session: - raise error.TestFail("Could not log into guest") + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm) try: - logging.info("Logged in") - if params.get("shutdown_method") == "shell": # Send a shutdown command to the guest's shell session.sendline(vm.get_params().get("shutdown_command")) @@ -134,33 +112,23 @@ def run_migration(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_utils.env_get_vm(env, params.get("main_vm")) - if not vm: - raise error.TestError("VM object not found in environment") - if not vm.is_alive(): - raise error.TestError("VM seems to be dead; Test requires a living VM") + 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") - dest_vm = vm.clone() - dest_vm.create(for_migration=True) - # Log into guest and get the output of migration_test_command - logging.info("Waiting for guest to be up...") - - session = kvm_utils.wait_for(vm.remote_login, 240, 0, 2) - if not session: - raise error.TestFail("Could not log into guest") - - logging.info("Logged in") - - reference_output = session.get_command_output(params.get("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) + # Define the migration command cmd = "migrate -d tcp:localhost:%d" % dest_vm.migration_port logging.debug("Migration command: %s" % cmd) @@ -211,7 +179,7 @@ def run_migration(test, params, env): logging.info("Logged in after migration") - output = session.get_command_output(params.get("migration_test_command")) + output = session.get_command_output(migration_test_command) session.close() # Compare output to reference output @@ -225,6 +193,7 @@ def run_migration(test, params, env): raise error.TestFail("Command produced different output before and " "after migration") + # Replace the main VM with the new cloned VM kvm_utils.env_register_vm(env, params.get("main_vm"), dest_vm) @@ -236,19 +205,8 @@ def run_autotest(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_utils.env_get_vm(env, params.get("main_vm")) - if not vm: - raise error.TestError("VM object not found in environment") - if not vm.is_alive(): - raise error.TestError("VM seems to be dead; Test requires a living VM") - - logging.info("Logging into guest...") - - session = kvm_utils.wait_for(vm.remote_login, 240, 0, 2) - if not session: - raise error.TestFail("Could not log into guest") - - logging.info("Logged in") + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm) # Collect some info test_name = params.get("test_name") @@ -426,25 +384,8 @@ def run_yum_update(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_utils.env_get_vm(env, params.get("main_vm")) - if not vm: - message = "VM object not found in environment" - logging.error(message) - raise error.TestError(message) - if not vm.is_alive(): - message = "VM seems to be dead; Test requires a living VM" - logging.error(message) - raise error.TestError(message) - - logging.info("Logging into guest...") - - session = kvm_utils.wait_for(vm.remote_login, 240, 0, 2) - if not session: - message = "Could not log into guest" - logging.error(message) - raise error.TestFail(message) - - logging.info("Logged in") + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm) internal_yum_update(session, "yum update", params.get("shell_prompt"), 600) internal_yum_update(session, "yum update kernel", @@ -461,21 +402,10 @@ def run_linux_s3(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_utils.env_get_vm(env, params.get("main_vm")) - if not vm: - raise error.TestError("VM object not found in environment") - if not vm.is_alive(): - raise error.TestError("VM seems to be dead; Test requires a living VM") - - logging.info("Waiting for guest to be up...") - - session = kvm_utils.wait_for(vm.remote_login, 240, 0, 2) - if not session: - raise error.TestFail("Could not log into guest") + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm) - logging.info("Logged in") logging.info("Checking that VM supports S3") - status = session.get_command_status("grep -q mem /sys/power/state") if status == None: logging.error("Failed to check if S3 exists") @@ -520,11 +450,7 @@ def run_stress_boot(tests, params, env): @param env: Dictionary with test environment. """ # boot the first vm - vm = kvm_utils.env_get_vm(env, params.get("main_vm")) - if not vm: - raise error.TestError("VM object not found in environment") - if not vm.is_alive(): - raise error.TestError("VM seems to be dead; Test requires a living VM") + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) logging.info("Waiting for first guest to be up...") @@ -645,19 +571,8 @@ def run_timedrift(test, params, env): guest_time = time.mktime(time.strptime(s, time_format)) return (host_time, guest_time) - vm = kvm_utils.env_get_vm(env, params.get("main_vm")) - if not vm: - raise error.TestError("VM object not found in environment") - if not vm.is_alive(): - raise error.TestError("VM seems to be dead; Test requires a living VM") - - logging.info("Waiting for guest to be up...") - - session = kvm_utils.wait_for(vm.remote_login, 240, 0, 2) - if not session: - raise error.TestFail("Could not log into guest") - - logging.info("Logged in") + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm) # Collect test parameters: # Command to run to get the current time @@ -781,20 +696,11 @@ def run_autoit(test, params, env): @param params: Dictionary with test parameters. @param env: Dictionary with the test environment. """ - vm = kvm_utils.env_get_vm(env, params.get("main_vm")) - if not vm: - raise error.TestError("VM object not found in environment") - if not vm.is_alive(): - raise error.TestError("VM seems to be dead; Test requires a living VM") - - logging.info("Waiting for guest to be up...") - - session = kvm_utils.wait_for(vm.remote_login, 240, 0, 2) - if not session: - raise error.TestFail("Could not log into guest") + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm) try: - logging.info("Logged in; starting script...") + logging.info("Starting script...") # Collect test parameters binary = params.get("autoit_binary")