From patchwork Fri Jun 18 00:14:21 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 106773 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5I0F2md015806 for ; Fri, 18 Jun 2010 00:15:10 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760869Ab0FRAPE (ORCPT ); Thu, 17 Jun 2010 20:15:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47080 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760005Ab0FRAO4 (ORCPT ); Thu, 17 Jun 2010 20:14:56 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0EudQ004137 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 17 Jun 2010 20:14:56 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0ErxW016393; Thu, 17 Jun 2010 20:14:54 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o5I0EljK005733; Thu, 17 Jun 2010 20:14:52 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 04/18] KVM test: kvm_monitor.py: verify correctness of QMP transaction id Date: Fri, 18 Jun 2010 03:14:21 +0300 Message-Id: <1276820075-31310-4-git-send-email-mgoldish@redhat.com> In-Reply-To: <1276820075-31310-3-git-send-email-mgoldish@redhat.com> References: <1276820075-31310-1-git-send-email-mgoldish@redhat.com> <1276820075-31310-2-git-send-email-mgoldish@redhat.com> <1276820075-31310-3-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 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, 18 Jun 2010 00:15:11 +0000 (UTC) diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py index c2c6261..8d4a798 100644 --- a/client/tests/kvm/kvm_monitor.py +++ b/client/tests/kvm/kvm_monitor.py @@ -427,10 +427,12 @@ class QMPMonitor(Monitor): # Private methods - def _build_cmd(self, cmd, args=None): + def _build_cmd(self, cmd, args=None, id=None): obj = {"execute": cmd} - if args: + if args is not None: obj["arguments"] = args + if id is not None: + obj["id"] = id return obj @@ -467,7 +469,7 @@ class QMPMonitor(Monitor): return objs - def _send_command(self, cmd, args=None): + def _send_command(self, cmd, args=None, id=None): """ Send command without waiting for response. @@ -481,7 +483,7 @@ class QMPMonitor(Monitor): "QMP command '%s'" % cmd) try: - cmdobj = self._build_cmd(cmd, args) + cmdobj = self._build_cmd(cmd, args, id) try: self._socket.sendall(json.dumps(cmdobj) + "\n") except socket.error: @@ -514,20 +516,23 @@ class QMPMonitor(Monitor): # Read any data that might be available self._read_objects() # Send command - self._send_command(cmd, args) + id = kvm_utils.generate_random_string(8) + self._send_command(cmd, args, id) # Read response end_time = time.time() + timeout while time.time() < end_time: for obj in self._read_objects(): - if "return" in obj: - return obj["return"] - elif "error" in obj: - raise QMPCmdError("QMP command '%s' failed" % cmd, - obj["error"]) + if isinstance(obj, dict) and obj.get("id") == id: + if "return" in obj: + return obj["return"] + elif "error" in obj: + raise QMPCmdError("QMP command '%s' failed" % cmd, + obj["error"]) time.sleep(0.1) # No response found raise MonitorProtocolError("Received no response to QMP command " - "'%s'" % cmd) + "'%s', or received a response with an " + "incorrect id" % cmd) finally: self._lock.release()