From patchwork Mon Jan 3 18:27:11 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 448601 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 p03IQlhV023945 for ; Mon, 3 Jan 2011 18:27:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752025Ab1ACS05 (ORCPT ); Mon, 3 Jan 2011 13:26:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16249 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751960Ab1ACS04 (ORCPT ); Mon, 3 Jan 2011 13:26:56 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p03IQtT5021673 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 3 Jan 2011 13:26:56 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p03IQt4t021828; Mon, 3 Jan 2011 13:26:55 -0500 Received: from moof.tlv.redhat.com (dhcp-1-185.tlv.redhat.com [10.35.1.185]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p03IQeWc027298; Mon, 3 Jan 2011 13:26:54 -0500 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 10/17] KVM test: add VM.verify_alive() and Monitor.verify_responsive() Date: Mon, 3 Jan 2011 20:27:11 +0200 Message-Id: <1294079238-21239-10-git-send-email-mgoldish@redhat.com> In-Reply-To: <1294079238-21239-1-git-send-email-mgoldish@redhat.com> References: <1294079238-21239-1-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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.3 (demeter1.kernel.org [140.211.167.41]); Mon, 03 Jan 2011 18:27:00 +0000 (UTC) diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py index 7e6b594..6321fbd 100644 --- a/client/tests/kvm/kvm_monitor.py +++ b/client/tests/kvm/kvm_monitor.py @@ -128,6 +128,17 @@ class Monitor: return s + def is_responsive(self): + """ + Return True iff the monitor is responsive. + """ + try: + self.verify_responsive() + return True + except MonitorError: + return False + + class HumanMonitor(Monitor): """ Wraps "human monitor" commands. @@ -248,17 +259,11 @@ class HumanMonitor(Monitor): self._lock.release() - def is_responsive(self): + def verify_responsive(self): """ Make sure the monitor is responsive by sending a command. - - @return: True if responsive, False otherwise """ - try: - self.cmd("info status") - return True - except MonitorError: - return False + self.cmd("info status") # Command wrappers @@ -615,17 +620,11 @@ class QMPMonitor(Monitor): return self.cmd_obj(self._build_cmd(cmd, args, id), timeout) - def is_responsive(self): + def verify_responsive(self): """ Make sure the monitor is responsive by sending a command. - - @return: True if responsive, False otherwise """ - try: - self.cmd("query-status") - return True - except MonitorError: - return False + self.cmd("query-status") def get_events(self): diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py index dc943cf..d236359 100755 --- a/client/tests/kvm/kvm_vm.py +++ b/client/tests/kvm/kvm_vm.py @@ -856,6 +856,7 @@ class VM: monitor = kvm_monitor.HumanMonitor( monitor_name, self.get_monitor_filename(monitor_name)) + monitor.verify_responsive() break except kvm_monitor.MonitorError, e: logging.warn(e) @@ -998,15 +999,25 @@ class VM: return self.monitors[0] + def verify_alive(self): + """ + Make sure the VM is alive and that the main monitor is responsive. + + @raise VMDeadError: If the VM is dead + @raise: Various monitor exceptions if the monitor is unresponsive + """ + if self.is_dead(): + raise VMDeadError("VM is dead") + if self.monitors: + self.monitor.verify_responsive() + + def is_alive(self): """ Return True if the VM is alive and its monitor is responsive. """ - # Check if the process is running - if self.is_dead(): - return False - # Try sending a monitor command - return bool(self.monitor) and self.monitor.is_responsive() + return not self.is_dead() and (not self.monitors or + self.monitor.is_responsive()) def is_dead(self):