From: Michael Goldish <mgoldish@redhat.com>
To: autotest@test.kernel.org, kvm@vger.kernel.org
Cc: Michael Goldish <mgoldish@redhat.com>
Subject: [KVM-AUTOTEST PATCH 5/7] KVM test: kvm_monitor.py: replace MonitorSendError with MonitorSocketError
Date: Sun, 24 Oct 2010 13:01:08 +0200 [thread overview]
Message-ID: <1287918070-4579-5-git-send-email-mgoldish@redhat.com> (raw)
In-Reply-To: <1287918070-4579-4-git-send-email-mgoldish@redhat.com>
- 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 <mgoldish@redhat.com>
---
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
next prev parent reply other threads:[~2010-10-24 11:01 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-24 11:01 [KVM-AUTOTEST PATCH 1/7] KVM test: simplify MAC address management Michael Goldish
2010-10-24 11:01 ` [KVM-AUTOTEST PATCH 2/7] KVM test: VM.get_address(): fix handling of multiple NICs Michael Goldish
2010-10-24 11:01 ` [KVM-AUTOTEST PATCH 3/7] [RFC] KVM test: remove all code related to the old MAC address pool method Michael Goldish
2010-10-24 11:01 ` [KVM-AUTOTEST PATCH 4/7] KVM test: get_ifname(): use self.instance instead of self.vnc_port Michael Goldish
2010-10-24 11:01 ` Michael Goldish [this message]
2010-10-24 11:01 ` [KVM-AUTOTEST PATCH 6/7] KVM test: refactor migration code Michael Goldish
2010-10-24 11:01 ` [KVM-AUTOTEST PATCH 7/7] [RFC] KVM test: migrate_cancel: allow for alternative spellings of 'cancelled' Michael Goldish
2010-10-26 13:08 ` Lucas Meneghel Rodrigues
2010-10-26 12:56 ` [KVM-AUTOTEST PATCH 3/7] [RFC] KVM test: remove all code related to the old MAC address pool method Lucas Meneghel Rodrigues
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1287918070-4579-5-git-send-email-mgoldish@redhat.com \
--to=mgoldish@redhat.com \
--cc=autotest@test.kernel.org \
--cc=kvm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox