From mboxrd@z Thu Jan 1 00:00:00 1970 From: Amos Kong Subject: [PATCH 1/3] KVM-test: introduce a verify_status method Date: Fri, 06 May 2011 23:03:33 +0800 Message-ID: <20110506150333.5847.56754.stgit@localhost6.localdomain6> References: Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Cc: lmr@redhat.com, kvm@vger.kernel.org To: autotest@test.kernel.org Return-path: 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 In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: 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(-) 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): """