From patchwork Mon Jun 28 07:45:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feng Yang X-Patchwork-Id: 108320 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 o5S7jt5Q032202 for ; Mon, 28 Jun 2010 07:45:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754178Ab0F1Hpx (ORCPT ); Mon, 28 Jun 2010 03:45:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54713 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753054Ab0F1Hpx (ORCPT ); Mon, 28 Jun 2010 03:45:53 -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.13.8/8.13.8) with ESMTP id o5S7jpHr018813 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 28 Jun 2010 03:45:51 -0400 Received: from localhost.localdomain (dhcp-91-72.nay.redhat.com [10.66.91.72]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5S7jnjM001201; Mon, 28 Jun 2010 03:45:50 -0400 From: Feng Yang To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Feng Yang Subject: [PATCH 1/2] KVM Test: Update cmd() help function in kvm_monitor.py to support parameters. Date: Mon, 28 Jun 2010 15:45:49 +0800 Message-Id: <1277711149-12009-1-git-send-email-fyang@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.3 (demeter.kernel.org [140.211.167.41]); Mon, 28 Jun 2010 07:45:55 +0000 (UTC) diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py index 8440835..af9ff21 100644 --- a/client/tests/kvm/kvm_monitor.py +++ b/client/tests/kvm/kvm_monitor.py @@ -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'" % @@ -258,9 +259,8 @@ class HumanMonitor(Monitor): def cmd(self, command, 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. @param command: Command to send @param timeout: Time duration to wait for (qemu) prompt after command @@ -486,6 +486,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 +602,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 +617,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):