From patchwork Fri Jul 23 08:31:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Yang X-Patchwork-Id: 113858 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6N8pN2r024654 for ; Fri, 23 Jul 2010 08:52:29 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752427Ab0GWIb5 (ORCPT ); Fri, 23 Jul 2010 04:31:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10337 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751756Ab0GWIb4 (ORCPT ); Fri, 23 Jul 2010 04:31:56 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6N8Vsqu002220 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Jul 2010 04:31:54 -0400 Received: from localhost.localdomain (dhcp-91-72.nay.redhat.com [10.66.91.72]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6N8Vq48007952; Fri, 23 Jul 2010 04:31:53 -0400 From: Feng Yang To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Feng Yang Subject: [PATCH V2] KVM Test: Update cmd() help function in kvm_monitor.py to support parameters. Date: Fri, 23 Jul 2010 16:31:51 +0800 Message-Id: <1279873911-32757-1-git-send-email-fyang@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 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.3 (demeter.kernel.org [140.211.167.41]); Fri, 23 Jul 2010 08:52:29 +0000 (UTC) diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py index 8440835..98d90d8 100644 --- a/client/tests/kvm/kvm_monitor.py +++ b/client/tests/kvm/kvm_monitor.py @@ -4,7 +4,7 @@ Interfaces to the QEMU monitor. @copyright: 2008-2010 Red Hat Inc. """ -import socket, time, threading, logging +import socket, time, threading, logging, re import kvm_utils try: import json @@ -188,6 +188,7 @@ class HumanMonitor(Monitor): try: try: + logging.debug("Send command: %s" % command) self._socket.sendall(command + "\n") except socket.error: raise MonitorSendError("Could not send monitor command '%s'" % @@ -256,13 +257,14 @@ class HumanMonitor(Monitor): # - A command wrapper should use self._help_str if it requires information # about the monitor's capabilities. - def cmd(self, command, timeout=20): + def cmd(self, cmdline, timeout=20): """ - Send a simple command with no parameters and return its output. - Should only be used for commands that take no parameters and are - implemented under the same name for both the human and QMP monitors. - - @param command: Command to send + Send a simple command with/without parameters and return its output. + Implemented under the same name for both the human and QMP monitors. + Command with parameters should in following format e.g.: + 'memsave val=0 size=10240 filename=memsave' + Command without parameter: 'memsave' + @param comline: Command to send @param timeout: Time duration to wait for (qemu) prompt after command @return: The output of the command @raise MonitorLockError: Raised if the lock cannot be acquired @@ -270,6 +272,10 @@ class HumanMonitor(Monitor): @raise MonitorProtocolError: Raised if the (qemu) prompt cannot be found after sending the command """ + command = cmdline.split()[0] + re_str = "(?<=\=)\w*" + command += " " + ' '.join(re.findall(re_str, cmdline)) + return self._get_command_output(command, timeout) @@ -486,6 +492,7 @@ class QMPMonitor(Monitor): try: cmdobj = self._build_cmd(cmd, args, id) try: + logging.debug("Send command: %s" % cmdobj) self._socket.sendall(json.dumps(cmdobj) + "\n") except socket.error: raise MonitorSendError("Could not send QMP command '%s'" % cmd) @@ -601,11 +608,13 @@ class QMPMonitor(Monitor): # Note: all of the following functions raise exceptions in a similar manner # to cmd() and _get_command_output(). - def cmd(self, command, timeout=20): + def cmd(self, cmdline, timeout=20): """ - Send a simple command with no parameters and return its output. - Should only be used for commands that take no parameters and are - implemented under the same name for both the human and QMP monitors. + Send a simple command with/without parameters and return its output. + Implemented under the same name for both the human and QMP monitors. + Command with parameters should in following format e.g.: + 'memsave val=0 size=10240 filename=memsave' + Command without parameter: 'memsave' @param command: Command to send @param timeout: Time duration to wait for response @@ -614,7 +623,20 @@ class QMPMonitor(Monitor): @raise MonitorSendError: Raised if the command cannot be sent @raise MonitorProtocolError: Raised if no response is received """ - return self._get_command_output(command, timeout=timeout) + cmdargs = cmdline.split() + command = cmdargs[0] + args = {} + for arg in cmdargs[1:]: + opt = arg.split('=') + try: + try: + value = int(opt[1]) + except ValueError: + value = opt[1] + args[opt[0]] = value + except: + logging.debug("Fail to create args, please check command") + return self._get_command_output(command, args, timeout=timeout) def quit(self):