From patchwork Sun Apr 10 22:49:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 697301 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p3AMoEoZ007566 for ; Sun, 10 Apr 2011 22:50:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758022Ab1DJWuB (ORCPT ); Sun, 10 Apr 2011 18:50:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57458 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757750Ab1DJWuA (ORCPT ); Sun, 10 Apr 2011 18:50:00 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3AMnwkP005761 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 10 Apr 2011 18:49:58 -0400 Received: from freedom.redhat.com (vpn-9-90.rdu.redhat.com [10.11.9.90]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p3AMnulb010623; Sun, 10 Apr 2011 18:49:57 -0400 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues Subject: [PATCH 1/2] KVM test: Introducing monitor commands and response logging Date: Sun, 10 Apr 2011 19:49:53 -0300 Message-Id: <1302475794-10361-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Sun, 10 Apr 2011 22:50:14 +0000 (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 --- 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"])