diff mbox

[KVM-AUTOTEST,5/7] KVM test: kvm_monitor.py: replace MonitorSendError with MonitorSocketError

Message ID 1287918070-4579-5-git-send-email-mgoldish@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael Goldish Oct. 24, 2010, 11:01 a.m. UTC
None
diff mbox

Patch

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)