From patchwork Fri May 6 15:03:33 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amos Kong X-Patchwork-Id: 762292 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 p46F3iDA010060 for ; Fri, 6 May 2011 15:03:44 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754969Ab1EFPDl (ORCPT ); Fri, 6 May 2011 11:03:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38572 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754742Ab1EFPDl (ORCPT ); Fri, 6 May 2011 11:03:41 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p46F3eJU013258 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 6 May 2011 11:03:40 -0400 Received: from localhost6.localdomain6 (vpn2-8-71.sin2.redhat.com [10.67.8.71]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p46F3Zvc026934; Fri, 6 May 2011 11:03:38 -0400 Subject: [PATCH 1/3] KVM-test: introduce a verify_status method To: autotest@test.kernel.org From: Amos Kong Cc: lmr@redhat.com, kvm@vger.kernel.org Date: Fri, 06 May 2011 23:03:33 +0800 Message-ID: <20110506150333.5847.56754.stgit@localhost6.localdomain6> In-Reply-To: References: User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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]); Fri, 06 May 2011 15:03:44 +0000 (UTC) This method is used to check if VM status is same as we expected. Signed-off-by: Amos Kong --- 0 files changed, 0 insertions(+), 0 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/client/virt/kvm_monitor.py b/client/virt/kvm_monitor.py index 7934b07..aff716a 100644 --- a/client/virt/kvm_monitor.py +++ b/client/virt/kvm_monitor.py @@ -282,6 +282,18 @@ class HumanMonitor(Monitor): self.cmd("info status", debug=False) + def verify_status(self, status): + """ + Verify VM status + + @param status: Optional VM status, 'running' or 'paused' + @return: return True if VM status is same as we expected + """ + o = self.cmd("info status", debug=False) + if status=='paused' or status=='running': + return (status in o) + + # Command wrappers # Notes: # - All of the following commands raise exceptions in a similar manner to @@ -650,6 +662,20 @@ class QMPMonitor(Monitor): self.cmd(cmd="query-status", debug=False) + def verify_status(self, status): + """ + Verify VM status + + @param status: Optional VM status, 'running' or 'paused' + @return: return True if VM status is same as we expected + """ + o = str(self.cmd(cmd="query-status", debug=False)) + if (status=='paused' and "u'running': False" in o): + return True + if (status=='running' and "u'running': True" in o): + return True + + def get_events(self): """ Return a list of the asynchronous events received since the last diff --git a/client/virt/kvm_vm.py b/client/virt/kvm_vm.py index 57fc61b..830ab2e 100644 --- a/client/virt/kvm_vm.py +++ b/client/virt/kvm_vm.py @@ -82,6 +82,15 @@ class VM(virt_vm.BaseVM): return not self.process or not self.process.is_alive() + def verify_status(self, status): + """ + Check VM status + + @param status: Optional VM status, 'running' or 'paused' + @raise VMStatusError: If the VM status is not same as parameter + """ + if not self.monitor.verify_status(status): + raise virt_vm.VMStatusError("VM status is unexpected.") def clone(self, name=None, params=None, root_dir=None, address_cache=None, diff --git a/client/virt/virt_vm.py b/client/virt/virt_vm.py index fd28966..5e9838a 100644 --- a/client/virt/virt_vm.py +++ b/client/virt/virt_vm.py @@ -185,6 +185,8 @@ class VMMigrateStateMismatchError(VMMigrateError): class VMRebootError(VMError): pass +class VMStatusError(VMError): + pass def get_image_filename(params, root_dir): """