From patchwork Wed Oct 7 17:54:19 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 52321 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 n97I5tBD015201 for ; Wed, 7 Oct 2009 18:05:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753436AbZJGR6S (ORCPT ); Wed, 7 Oct 2009 13:58:18 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1759489AbZJGR6S (ORCPT ); Wed, 7 Oct 2009 13:58:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32722 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757840AbZJGR6O (ORCPT ); Wed, 7 Oct 2009 13:58:14 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n97HvmUA010572; Wed, 7 Oct 2009 13:57:48 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n97HvlWN002275; Wed, 7 Oct 2009 13:57:47 -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 n97Hve87014834; Wed, 7 Oct 2009 13:57:46 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 4/7] KVM test: move the reboot code to kvm_test_utils.py Date: Wed, 7 Oct 2009 19:54:19 +0200 Message-Id: <1254938062-15286-4-git-send-email-mgoldish@redhat.com> In-Reply-To: <1254938062-15286-3-git-send-email-mgoldish@redhat.com> References: <1254938062-15286-1-git-send-email-mgoldish@redhat.com> <1254938062-15286-2-git-send-email-mgoldish@redhat.com> <1254938062-15286-3-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 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 db9f666..4d7b1c3 100644 --- a/client/tests/kvm/kvm_test_utils.py +++ b/client/tests/kvm/kvm_test_utils.py @@ -61,6 +61,50 @@ def wait_for_login(vm, nic_index=0, timeout=240): return session +def reboot(vm, session, method="shell", sleep_before_reset=10, nic_index=0, + timeout=240): + """ + Reboot the VM and wait for it to come back up by trying to log in until + timeout expires. + + @param vm: VM object. + @param session: A shell session object. + @param method: Reboot method. Can be "shell" (send a shell reboot + command) or "system_reset" (send a system_reset monitor command). + @param nic_index: Index of NIC to access in the VM, when logging in after + rebooting. + @param timeout: Time to wait before giving up (after rebooting). + @return: A new shell session object. + """ + if method == "shell": + # Send a reboot command to the guest's shell + session.sendline(vm.get_params().get("reboot_command")) + logging.info("Reboot command sent; waiting for guest to go down...") + elif method == "system_reset": + # Sleep for a while before sending the command + time.sleep(sleep_before_reset) + # Send a system_reset monitor command + vm.send_monitor_cmd("system_reset") + logging.info("system_reset monitor command sent; waiting for guest to " + "go down...") + else: + logging.error("Unknown reboot method: %s" % method) + + # Wait for the session to become unresponsive and close it + if not kvm_utils.wait_for(lambda: not session.is_responsive(), 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...") + session = kvm_utils.wait_for(lambda: vm.remote_login(nic_index=nic_index), + timeout, 0, 2) + if not session: + raise error.TestFail("Could not log into guest after reboot") + logging.info("Guest is up again") + return session + + def migrate(vm, env=None): """ Migrate a VM locally and re-register it in the environment. diff --git a/client/tests/kvm/tests/boot.py b/client/tests/kvm/tests/boot.py index 282efda..cd1f1d4 100644 --- a/client/tests/kvm/tests/boot.py +++ b/client/tests/kvm/tests/boot.py @@ -19,33 +19,14 @@ def run_boot(test, params, env): session = kvm_test_utils.wait_for_login(vm) try: - if params.get("reboot_method") == "shell": - # Send a reboot command to the guest's shell - session.sendline(vm.get_params().get("reboot_command")) - logging.info("Reboot command sent; waiting for guest to go " - "down...") - elif params.get("reboot_method") == "system_reset": - # Sleep for a while -- give the guest a chance to finish booting - time.sleep(float(params.get("sleep_before_reset", 10))) - # Send a system_reset monitor command - vm.send_monitor_cmd("system_reset") - logging.info("system_reset monitor command sent; waiting for " - "guest to go down...") - else: return + if not params.get("reboot_method"): + return - # Wait for the session to become unresponsive - if not kvm_utils.wait_for(lambda: not session.is_responsive(), - 120, 0, 1): - raise error.TestFail("Guest refuses to go down") + # Reboot the VM + session = kvm_test_utils.reboot(vm, session, + params.get("reboot_method"), + float(params.get("sleep_before_reset", + 10))) finally: session.close() - - logging.info("Guest is down; waiting for it to go up again...") - - session = kvm_utils.wait_for(vm.remote_login, 240, 0, 2) - if not session: - raise error.TestFail("Could not log into guest after reboot") - session.close() - - logging.info("Guest is up again")