diff mbox

[1/2] KVM test: Introducing monitor commands and response logging

Message ID 1302475794-10361-1-git-send-email-lmr@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Lucas Meneghel Rodrigues April 10, 2011, 10:49 p.m. UTC
In several KVM tests, it is very useful to log commands sent
to the monitor and their responses, but most of the time
output from such commands in verify_responsive and screendump
threads are not necessary. So, introduce the param debug in
monitor.cmd(), that defaults to True, and then later turn
off selectively outputs from the parts of the framework
where monitor commands are excessively called and their
output is not so interesting.

Signed-off-by: Lucas Meneghel Rodrigues <lmr@redhat.com>
---
 client/tests/kvm/kvm_monitor.py |   23 +++++++++++++++++++++--
 1 files changed, 21 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py
index 8cf2441..507e8dd 100644
--- a/client/tests/kvm/kvm_monitor.py
+++ b/client/tests/kvm/kvm_monitor.py
@@ -228,18 +228,22 @@  class HumanMonitor(Monitor):
 
     # Public methods
 
-    def cmd(self, command, timeout=20):
+    def cmd(self, command, timeout=20, debug=True):
         """
         Send command to the monitor.
 
         @param command: Command to send to the monitor
         @param timeout: Time duration to wait for the (qemu) prompt to return
+        @param debug: Whether to print the commands being sent and responses
         @return: Output received from the monitor
         @raise MonitorLockError: Raised if the lock cannot be acquired
         @raise MonitorSocketError: Raised if a socket error occurs
         @raise MonitorProtocolError: Raised if the (qemu) prompt cannot be
                 found after sending the command
         """
+        if debug:
+            logging.debug("(monitor %s) Sending command '%s'",
+                          self.name, command)
         if not self._acquire_lock(20):
             raise MonitorLockError("Could not acquire exclusive lock to send "
                                    "monitor command '%s'" % command)
@@ -255,6 +259,12 @@  class HumanMonitor(Monitor):
             o = "\n".join(o.splitlines()[1:])
             # Report success/failure
             if s:
+                if debug and o:
+                    logging.debug("(monitor %s) "
+                                  "Response to '%s'", self.name,
+                                  command)
+                    for l in o.splitlines():
+                        logging.debug("(monitor %s)    %s", self.name, l)
                 return o
             else:
                 msg = ("Could not find (qemu) prompt after command '%s'. "
@@ -514,7 +524,7 @@  class QMPMonitor(Monitor):
 
     # Public methods
 
-    def cmd(self, cmd, args=None, timeout=20):
+    def cmd(self, cmd, args=None, timeout=20, debug=True):
         """
         Send a QMP monitor command and return the response.
 
@@ -532,6 +542,9 @@  class QMPMonitor(Monitor):
                 (the exception's args are (cmd, args, data) where data is the
                 error data)
         """
+        if debug:
+            logging.debug("(monitor %s) Sending command '%s'",
+                          self.name, cmd)
         if not self._acquire_lock(20):
             raise MonitorLockError("Could not acquire exclusive lock to send "
                                    "QMP command '%s'" % cmd)
@@ -550,6 +563,12 @@  class QMPMonitor(Monitor):
                                            "response with an incorrect id"
                                            % cmd)
             if "return" in r:
+                if debug and r["return"]:
+                    logging.debug("(monitor %s) "
+                                  "Response to '%s'", self.name, cmd)
+                    o = str(r["return"])
+                    for l in o.splitlines():
+                        logging.debug("(monitor %s)    %s", self.name, l)
                 return r["return"]
             if "error" in r:
                 raise QMPCmdError(cmd, args, r["error"])