From patchwork Tue Jan 11 13:13:21 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 471551 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p0BDEHT1008472 for ; Tue, 11 Jan 2011 13:14:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932151Ab1AKNNd (ORCPT ); Tue, 11 Jan 2011 08:13:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:31058 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932106Ab1AKNNY (ORCPT ); Tue, 11 Jan 2011 08:13:24 -0500 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 p0BDDNtZ009581 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Jan 2011 08:13:23 -0500 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 p0BDDNrl022802; Tue, 11 Jan 2011 08:13:23 -0500 Received: from qu0061.eng.lab.tlv.redhat.com ([10.35.16.61]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p0BDD9nV025030; Tue, 11 Jan 2011 08:13:22 -0500 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 09/26] KVM test: make reboot() a VM method Date: Tue, 11 Jan 2011 15:13:21 +0200 Message-Id: <1294751618-21631-9-git-send-email-mgoldish@redhat.com> In-Reply-To: <1294751618-21631-1-git-send-email-mgoldish@redhat.com> References: <1294751618-21631-1-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 X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Tue, 11 Jan 2011 13:14:19 +0000 (UTC) diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index b0b3ea6..525c065 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -157,6 +157,10 @@ class VMMigrateStateMismatchError(VMMigrateError): (self.src_hash, self.dst_hash)) +class VMRebootError(VMError): + pass + + def get_image_filename(params, root_dir): """ Generate an image path from params and root_dir. @@ -1503,6 +1507,56 @@ class VM: clone.destroy(gracefully=False) + @error.context_aware + def reboot(self, session=None, method="shell", 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 session: A shell session object or None. + @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 for login to succeed (after rebooting). + @return: A new shell session object. + """ + error.base_context("rebooting '%s'" % self.name, logging.info) + error.context("before reboot") + session = session or self.login() + error.context() + + if method == "shell": + session.sendline(self.params.get("reboot_command")) + elif method == "system_reset": + # Clear the event list of all QMP monitors + qmp_monitors = [m for m in self.monitors if m.protocol == "qmp"] + for m in qmp_monitors: + m.clear_events() + # Send a system_reset monitor command + self.monitor.cmd("system_reset") + # Look for RESET QMP events + time.sleep(1) + for m in qmp_monitors: + if m.get_event("RESET"): + logging.info("RESET QMP event received") + else: + raise VMRebootError("RESET QMP event not received after " + "system_reset (monitor '%s')" % m.name) + else: + raise VMRebootError("Unknown reboot method: %s" % method) + + error.context("waiting for guest to go down", logging.info) + if not kvm_utils.wait_for(lambda: + not session.is_responsive(timeout=30), + 120, 0, 1): + raise VMRebootError("Guest refuses to go down") + session.close() + + error.context("logging in after reboot", logging.info) + return self.wait_for_login(nic_index, timeout=timeout) + + def send_key(self, keystr): """ Send a key event to the VM.