From mboxrd@z Thu Jan 1 00:00:00 1970 From: 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> 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> Cc: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Return-path: 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 In-Reply-To: <1287918070-4579-4-git-send-email-mgoldish@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: - Replace MonitorSendError with MonitorSocketError. - Embed socket.error messages in MonitorSocketError messages. - Catch exceptions raised while receiving data (in addition to those raised while sending data). Signed-off-by: Michael Goldish --- client/tests/kvm/kvm_monitor.py | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-) 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) -- 1.5.5.6