In _get_command_output(), instead of just looking for an object with a 'return' or 'error' key, look for an object with the same unique transaction id given in the command. Also modify exception message accordingly. Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx> --- client/tests/kvm/kvm_monitor.py | 27 ++++++++++++++++----------- 1 files changed, 16 insertions(+), 11 deletions(-) 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() -- 1.5.4.1 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html