Signed-off-by: Michael Goldish <[email protected]>
---
client/tests/kvm/kvm_monitor.py | 31 +++++++++++++++----------------
client/tests/kvm/kvm_vm.py | 21 ++++++++++++++++-----
2 files changed, 31 insertions(+), 21 deletions(-)
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):
--
1.7.3.4
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html