Receive a socket.error exception and store it as an attribute. It's cleaner and probably a bit easier to maintain than embedding the error message in the string passed to the constructor. Signed-off-by: Michael Goldish <mgoldish@xxxxxxxxxx> --- client/tests/kvm/kvm_monitor.py | 19 ++++++++++++------- 1 files changed, 12 insertions(+), 7 deletions(-) diff --git a/client/tests/kvm/kvm_monitor.py b/client/tests/kvm/kvm_monitor.py index 48d627f..8cf2441 100644 --- a/client/tests/kvm/kvm_monitor.py +++ b/client/tests/kvm/kvm_monitor.py @@ -22,7 +22,13 @@ class MonitorConnectError(MonitorError): class MonitorSocketError(MonitorError): - pass + def __init__(self, msg, e): + Exception.__init__(self, msg, e) + self.msg = msg + self.e = e + + def __str__(self): + return "%s (%s)" % (self.msg, self.e) class MonitorLockError(MonitorError): @@ -120,8 +126,8 @@ class Monitor: try: data = self._socket.recv(1024) except socket.error, e: - raise MonitorSocketError("Could not receive data from monitor " - "(%s)" % e) + raise MonitorSocketError("Could not receive data from monitor", + e) if not data: break s += data @@ -213,8 +219,8 @@ class HumanMonitor(Monitor): try: self._socket.sendall(cmd + "\n") except socket.error, e: - raise MonitorSocketError("Could not send monitor command %r " - "(%s)" % (cmd, e)) + raise MonitorSocketError("Could not send monitor command %r" % + cmd, e) finally: self._lock.release() @@ -485,8 +491,7 @@ class QMPMonitor(Monitor): try: self._socket.sendall(data) except socket.error, e: - raise MonitorSocketError("Could not send data: %r (%s)" % - (data, e)) + raise MonitorSocketError("Could not send data: %r" % data, e) def _get_response(self, id=None, timeout=20): -- 1.7.3.4 -- 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