summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorlmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4>2011-05-21 04:57:35 +0000
committerlmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4>2011-05-21 04:57:35 +0000
commitf16f5cbdf182b1c249955d3864339f02f920c972 (patch)
tree7edeb42ebe3c9578cb2694412ad5bff1b0dd592f /client
parentd26dcdce49bb12302db363752ab4abb5e34c4e2f (diff)
KVM-test: introduce a verify_status method
This method is used to check if VM status is same as we expected. Signed-off-by: Amos Kong <akong@redhat.com> git-svn-id: svn://test.kernel.org/autotest/trunk@5369 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'client')
-rw-r--r--client/virt/kvm_monitor.py26
-rw-r--r--client/virt/kvm_vm.py9
-rw-r--r--client/virt/virt_vm.py2
3 files changed, 37 insertions, 0 deletions
diff --git a/client/virt/kvm_monitor.py b/client/virt/kvm_monitor.py
index 7934b071..aff716a5 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 57fc61b5..c9bb2733 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 f7d672c9..983ee026 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):
"""