ia64/xen-unstable
changeset 8348:d37644abe52d
When we see a httplib.BadStatusLine, sleep 5 seconds and then retry. This
happens when Xend crashes, so retrying once allows it to restart and recover.
If we see Xend crash twice, we give up, but throw a more polite exception than
the BadStatusLine splat that we got previously.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
happens when Xend crashes, so retrying once allows it to restart and recover.
If we see Xend crash twice, we give up, but throw a more polite exception than
the BadStatusLine splat that we got previously.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | emellor@leeni.uk.xensource.com |
---|---|
date | Tue Dec 13 18:07:51 2005 +0000 (2005-12-13) |
parents | 95f84e37c90d |
children | 8c5b7b6772ae |
files | tools/python/xen/xend/XendProtocol.py |
line diff
1.1 --- a/tools/python/xen/xend/XendProtocol.py Tue Dec 13 18:06:03 2005 +0000 1.2 +++ b/tools/python/xen/xend/XendProtocol.py Tue Dec 13 18:07:51 2005 +0000 1.3 @@ -13,10 +13,12 @@ 1.4 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1.5 #============================================================================ 1.6 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com> 1.7 +# Copyright (C) 2005 XenSource Ltd. 1.8 #============================================================================ 1.9 1.10 import socket 1.11 import httplib 1.12 +import time 1.13 import types 1.14 1.15 from encode import * 1.16 @@ -165,24 +167,38 @@ class HttpXendClientProtocol(XendClientP 1.17 @param method: http method: POST or GET 1.18 @param args: request arguments (dict) 1.19 """ 1.20 - self.request = self.makeRequest(url, method, args) 1.21 - conn = self.makeConnection(url) 1.22 - if DEBUG: conn.set_debuglevel(1) 1.23 - conn.request(method, url.fullpath(), self.request.data, self.request.headers) 1.24 - resp = conn.getresponse() 1.25 - self.resp = resp 1.26 - val = self.handleStatus(resp.version, resp.status, resp.reason) 1.27 - if val is None: 1.28 - data = None 1.29 - else: 1.30 - data = resp.read() 1.31 - conn.close() 1.32 - val = self.handleResponse(data) 1.33 - return val 1.34 + retries = 0 1.35 + while retries < 2: 1.36 + self.request = self.makeRequest(url, method, args) 1.37 + conn = self.makeConnection(url) 1.38 + try: 1.39 + if DEBUG: conn.set_debuglevel(1) 1.40 + conn.request(method, url.fullpath(), self.request.data, 1.41 + self.request.headers) 1.42 + try: 1.43 + resp = conn.getresponse() 1.44 + self.resp = resp 1.45 + val = self.handleStatus(resp.version, resp.status, 1.46 + resp.reason) 1.47 + if val is None: 1.48 + data = None 1.49 + else: 1.50 + data = resp.read() 1.51 + val = self.handleResponse(data) 1.52 + return val 1.53 + except httplib.BadStatusLine: 1.54 + retries += 1 1.55 + time.sleep(5) 1.56 + finally: 1.57 + conn.close() 1.58 + 1.59 + raise XendError("Received invalid response from Xend, twice.") 1.60 + 1.61 1.62 def getHeader(self, key): 1.63 return self.resp.getheader(key) 1.64 1.65 + 1.66 class UnixConnection(httplib.HTTPConnection): 1.67 """Subclass of Python library HTTPConnection that uses a unix-domain socket. 1.68 """