Retry http requests on timeouts
Change-Id: I3f2a658049f0f2190db9621b5376e499c11f63a1
This commit is contained in:
parent
ccd682d774
commit
910c82c501
@ -197,6 +197,9 @@ class MemoryMockAPIProvider(nsx_cluster.AbstractHTTPProvider):
|
|||||||
def is_connection_exception(self, exception):
|
def is_connection_exception(self, exception):
|
||||||
return isinstance(exception, requests_exceptions.ConnectionError)
|
return isinstance(exception, requests_exceptions.ConnectionError)
|
||||||
|
|
||||||
|
def is_timeout_exception(self, exception):
|
||||||
|
return isinstance(exception, requests_exceptions.Timeout)
|
||||||
|
|
||||||
|
|
||||||
class NsxClientTestCase(NsxLibTestCase):
|
class NsxClientTestCase(NsxLibTestCase):
|
||||||
|
|
||||||
|
@ -86,6 +86,13 @@ class AbstractHTTPProvider(object):
|
|||||||
Return True if it's a connection exception and False otherwise.
|
Return True if it's a connection exception and False otherwise.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
|
def is_timeout_exception(self, exception):
|
||||||
|
"""Determine if the given exception is related to timeout.
|
||||||
|
|
||||||
|
Return True if it's a timeout exception and False otherwise.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class TimeoutSession(requests.Session):
|
class TimeoutSession(requests.Session):
|
||||||
"""Extends requests.Session to support timeout at the session level."""
|
"""Extends requests.Session to support timeout at the session level."""
|
||||||
@ -229,6 +236,9 @@ class NSXRequestsHTTPProvider(AbstractHTTPProvider):
|
|||||||
def is_connection_exception(self, exception):
|
def is_connection_exception(self, exception):
|
||||||
return isinstance(exception, requests_exceptions.ConnectionError)
|
return isinstance(exception, requests_exceptions.ConnectionError)
|
||||||
|
|
||||||
|
def is_timeout_exception(self, exception):
|
||||||
|
return isinstance(exception, requests_exceptions.Timeout)
|
||||||
|
|
||||||
def is_conn_open_exception(self, exception):
|
def is_conn_open_exception(self, exception):
|
||||||
return isinstance(exception, requests_exceptions.ConnectTimeout)
|
return isinstance(exception, requests_exceptions.ConnectTimeout)
|
||||||
|
|
||||||
@ -628,8 +638,9 @@ class ClusteredAPI(object):
|
|||||||
return response
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.warning("Request failed due to: %s", e)
|
LOG.warning("Request failed due to: %s", e)
|
||||||
if not self._http_provider.is_connection_exception(e):
|
if (not self._http_provider.is_connection_exception(e) and
|
||||||
# only trap and retry connection errors
|
not self._http_provider.is_timeout_exception(e)):
|
||||||
|
# only trap and retry connection & timeout errors
|
||||||
raise e
|
raise e
|
||||||
if self._http_provider.is_conn_open_exception(e):
|
if self._http_provider.is_conn_open_exception(e):
|
||||||
# unable to establish new connection - endpoint is
|
# unable to establish new connection - endpoint is
|
||||||
|
Loading…
x
Reference in New Issue
Block a user