NSX: Add ability to retry on 503's returned by the controller
There are a number of circumstances where the NSX controller may return 503. Currently the API client does not retry, so this patch adds a retry logic with timeout. Closes-bug: #1284277 Change-Id: I85df087d5ae409e6cb5c35eb171e89346abe81f4
This commit is contained in:
@@ -128,17 +128,21 @@ class EventletApiRequest(request.ApiRequest):
|
|||||||
def _handle_request(self):
|
def _handle_request(self):
|
||||||
'''First level request handling.'''
|
'''First level request handling.'''
|
||||||
attempt = 0
|
attempt = 0
|
||||||
|
timeout = 0
|
||||||
response = None
|
response = None
|
||||||
while response is None and attempt <= self._retries:
|
while response is None and attempt <= self._retries:
|
||||||
eventlet.greenthread.sleep(0)
|
eventlet.greenthread.sleep(timeout)
|
||||||
attempt += 1
|
attempt += 1
|
||||||
|
|
||||||
req = self._issue_request()
|
req = self._issue_request()
|
||||||
# automatically raises any exceptions returned.
|
# automatically raises any exceptions returned.
|
||||||
if isinstance(req, httplib.HTTPResponse):
|
if isinstance(req, httplib.HTTPResponse):
|
||||||
|
timeout = 0
|
||||||
if attempt <= self._retries and not self._abort:
|
if attempt <= self._retries and not self._abort:
|
||||||
if (req.status == httplib.UNAUTHORIZED
|
if req.status in (httplib.UNAUTHORIZED, httplib.FORBIDDEN):
|
||||||
or req.status == httplib.FORBIDDEN):
|
continue
|
||||||
|
elif req.status == httplib.SERVICE_UNAVAILABLE:
|
||||||
|
timeout = 0.5
|
||||||
continue
|
continue
|
||||||
# else fall through to return the error code
|
# else fall through to return the error code
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user