[PATCH 1/3] KVM-test: introduce a verify_status method

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This method is used to check if VM status is same as
we expected.

Signed-off-by: Amos Kong <akong@xxxxxxxxxx>
---
 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):
     """

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux