From: Lucas Meneghel Rodrigues <lmr@redhat.com>
To: autotest@test.kernel.org
Cc: kvm@vger.kernel.org
Subject: [PATCH 1/2] KVM test: Introducing monitor commands and response logging
Date: Sun, 10 Apr 2011 19:49:53 -0300 [thread overview]
Message-ID: <1302475794-10361-1-git-send-email-lmr@redhat.com> (raw)
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 --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"])
--
1.7.4.2
next reply other threads:[~2011-04-10 22:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-10 22:49 Lucas Meneghel Rodrigues [this message]
2011-04-10 22:49 ` [PATCH 2/2] KVM test: Turning off debug output for frequently called monitor commands Lucas Meneghel Rodrigues
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1302475794-10361-1-git-send-email-lmr@redhat.com \
--to=lmr@redhat.com \
--cc=autotest@test.kernel.org \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.