From patchwork Sun Oct 24 11:01:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 265432 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 o9OB1RJ4008706 for ; Sun, 24 Oct 2010 11:01:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932484Ab0JXLBX (ORCPT ); Sun, 24 Oct 2010 07:01:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26963 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932459Ab0JXLBV (ORCPT ); Sun, 24 Oct 2010 07:01:21 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9OB1Kwv029191 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 24 Oct 2010 07:01:20 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id o9OB1JVn025193; Sun, 24 Oct 2010 07:01:20 -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 o9OB1BC7007247; Sun, 24 Oct 2010 07:01:18 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [KVM-AUTOTEST PATCH 5/7] KVM test: kvm_monitor.py: replace MonitorSendError with MonitorSocketError Date: Sun, 24 Oct 2010 13:01:08 +0200 Message-Id: <1287918070-4579-5-git-send-email-mgoldish@redhat.com> In-Reply-To: <1287918070-4579-4-git-send-email-mgoldish@redhat.com> References: <1287918070-4579-1-git-send-email-mgoldish@redhat.com> <1287918070-4579-2-git-send-email-mgoldish@redhat.com> <1287918070-4579-3-git-send-email-mgoldish@redhat.com> <1287918070-4579-4-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 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 (demeter1.kernel.org [140.211.167.41]); Sun, 24 Oct 2010 11:01:28 +0000 (UTC) diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py index 7047850..e0365cd 100644 --- a/client/tests/kvm/kvm_monitor.py +++ b/client/tests/kvm/kvm_monitor.py @@ -21,7 +21,7 @@ class MonitorConnectError(MonitorError): pass -class MonitorSendError(MonitorError): +class MonitorSocketError(MonitorError): pass @@ -111,7 +111,11 @@ class Monitor: def _recvall(self): s = "" while self._data_available(): - data = self._socket.recv(1024) + try: + data = self._socket.recv(1024) + except socket.error, (errno, msg): + raise MonitorSocketError("Could not receive data from monitor " + "(%s)" % msg) if not data: break s += data @@ -164,7 +168,7 @@ class HumanMonitor(Monitor): s = "" end_time = time.time() + timeout while self._data_available(end_time - time.time()): - data = self._socket.recv(1024) + data = self._recvall() if not data: break s += data @@ -182,7 +186,7 @@ class HumanMonitor(Monitor): @param cmd: Command to send @raise MonitorLockError: Raised if the lock cannot be acquired - @raise MonitorSendError: Raised if the command cannot be sent + @raise MonitorSocketError: Raised if a socket error occurs """ if not self._acquire_lock(20): raise MonitorLockError("Could not acquire exclusive lock to send " @@ -191,9 +195,9 @@ class HumanMonitor(Monitor): try: try: self._socket.sendall(cmd + "\n") - except socket.error: - raise MonitorSendError("Could not send monitor command '%s'" % - cmd) + except socket.error, (errno, msg): + raise MonitorSocketError("Could not send monitor command '%s' " + "(%s)" % (cmd, msg)) finally: self._lock.release() @@ -209,7 +213,7 @@ class HumanMonitor(Monitor): @param timeout: Time duration to wait for the (qemu) prompt to return @return: Output received from the monitor @raise MonitorLockError: Raised if the lock cannot be acquired - @raise MonitorSendError: Raised if the command cannot be sent + @raise MonitorSocketError: Raised if a socket error occurs @raise MonitorProtocolError: Raised if the (qemu) prompt cannot be found after sending the command """ @@ -465,12 +469,13 @@ class QMPMonitor(Monitor): Send raw data without waiting for response. @param data: Data to send - @raise MonitorSendError: Raised if the data cannot be sent + @raise MonitorSocketError: Raised if a socket error occurs """ try: self._socket.sendall(data) - except socket.error: - raise MonitorSendError("Could not send data: %r" % data) + except socket.error, (errno, msg): + raise MonitorSocketError("Could not send data: %r (%s)" % + (data, msg)) def _get_response(self, id=None, timeout=20): @@ -505,7 +510,7 @@ class QMPMonitor(Monitor): @param timeout: Time duration to wait for response @return: The response received @raise MonitorLockError: Raised if the lock cannot be acquired - @raise MonitorSendError: Raised if the command cannot be sent + @raise MonitorSocketError: Raised if a socket error occurs @raise MonitorProtocolError: Raised if no response is received @raise QMPCmdError: Raised if the response is an error message (the exception's args are (cmd, args, data) where data is the @@ -547,7 +552,7 @@ class QMPMonitor(Monitor): @param timeout: Time duration to wait for response @return: The response received @raise MonitorLockError: Raised if the lock cannot be acquired - @raise MonitorSendError: Raised if the command cannot be sent + @raise MonitorSocketError: Raised if a socket error occurs @raise MonitorProtocolError: Raised if no response is received """ if not self._acquire_lock(20): @@ -578,7 +583,7 @@ class QMPMonitor(Monitor): @param timeout: Time duration to wait for response @return: The response received @raise MonitorLockError: Raised if the lock cannot be acquired - @raise MonitorSendError: Raised if the command cannot be sent + @raise MonitorSocketError: Raised if a socket error occurs @raise MonitorProtocolError: Raised if no response is received """ return self.cmd_raw(json.dumps(obj) + "\n") @@ -597,7 +602,7 @@ class QMPMonitor(Monitor): @param timeout: Time duration to wait for response @return: The response received @raise MonitorLockError: Raised if the lock cannot be acquired - @raise MonitorSendError: Raised if the command cannot be sent + @raise MonitorSocketError: Raised if a socket error occurs @raise MonitorProtocolError: Raised if no response is received """ return self.cmd_obj(self._build_cmd(cmd, args, id), timeout)