Retry on 503 Service Unavailable

When the NSX handles too many active requests, it may return HTTP
response 503.
We should handle it the same as 429 (Too many requests), and retry
the request.

Change-Id: I27c1142f5d896ce88c2d5aa70536ad0876efbcfa
This commit is contained in:
Adit Sarfaty 2018-05-27 12:25:59 +03:00
parent d1362ba0d9
commit dd8e561451
2 changed files with 14 additions and 4 deletions

View File

@ -43,7 +43,8 @@ def http_error_to_exception(status_code, error_code):
{'99': exceptions.ClientCertificateNotTrusted},
{'98': exceptions.BadXSRFToken}, exceptions.TooManyRequests} exceptions.TooManyRequests, exceptions.ServiceUnavailable}
if status_code in errors:
if isinstance(errors[status_code], dict):
@ -306,11 +307,12 @@ class NSX3Client(JSONRESTClient):
def _rest_call(self, url, **kwargs):
if self.rate_limit_retry:
# If too many requests are handled by the nsx at the same time,
# error "429: Too Many Requests" will be returned.
# error "429: Too Many Requests" or "503: Server Unavailable"
# will be returned.
# the client is expected to retry after a random 400-600 milli,
# and later exponentially until 5 seconds wait
def _rest_call_with_retry(self, url, **kwargs):
return super(NSX3Client, self)._rest_call(url, **kwargs)

View File

@ -101,7 +101,15 @@ class StaleRevision(ManagerError):
class TooManyRequests(ManagerError):
class ServerBusy(ManagerError):
class TooManyRequests(ServerBusy):
class ServiceUnavailable(ServerBusy):