diff options
author | lmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4> | 2011-04-11 02:02:05 +0000 |
---|---|---|
committer | lmr <lmr@592f7852-d20e-0410-864c-8624ca9c26a4> | 2011-04-11 02:02:05 +0000 |
commit | c6864699d4f5eaf5789fcf5fcf7f7a968bf1bd74 (patch) | |
tree | 74eaffc97ff692db4592f83f7ef92c01355746b4 /client | |
parent | 351c05d905d82b048219c950e1e0fb688537107c (diff) |
KVM test: Introducing monitor commands and response logging
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>
git-svn-id: svn://test.kernel.org/autotest/trunk@5314 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'client')
-rw-r--r-- | client/tests/kvm/kvm_monitor.py | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py index 8cf2441e..507e8dd4 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"]) |