Add search error code & retry

Retry V3 search requests in case of timeout error as well.

Change-Id: I9fde4b6319d31719e09246f1432b58b27097e16b
This commit is contained in:
Adit Sarfaty
2019-03-27 08:46:20 +02:00
parent 6ea09e7e8c
commit 5a4ab83eec
3 changed files with 12 additions and 2 deletions

View File

@@ -36,6 +36,7 @@ def http_error_to_exception(status_code, error_code):
'default': exceptions.ResourceNotFound},
requests.codes.BAD_REQUEST:
{'60508': exceptions.NsxIndexingInProgress,
'60514': exceptions.NsxSearchTimeout,
'500045': exceptions.NsxPendingDelete},
requests.codes.CONFLICT: exceptions.StaleRevision,
requests.codes.PRECONDITION_FAILED: exceptions.StaleRevision,

View File

@@ -152,11 +152,20 @@ class NsxSearchInvalidQuery(NsxLibException):
message = _("Invalid input for NSX search query. Reason: %(reason)s")
class NsxIndexingInProgress(NsxLibException):
class NsxSearchError(NsxLibException):
message = _("Search failed due to error")
class NsxIndexingInProgress(NsxSearchError):
message = _("Bad Request due to indexing is in progress, please retry "
"after sometime")
class NsxSearchTimeout(NsxSearchError):
message = _("Request timed out. This may occur when system is under load "
"or running low on resources")
class NsxPendingDelete(NsxLibException):
message = _("An object with the same name is marked for deletion. Either "
"use another path or wait for the purge cycle to permanently "

View File

@@ -137,7 +137,7 @@ class NsxLibBase(object):
cursor, page_size)
# Retry the search on case of error
@utils.retry_upon_exception(exceptions.NsxIndexingInProgress,
@utils.retry_upon_exception(exceptions.NsxSearchError,
max_attempts=self.client.max_attempts)
def do_search(url):
return self.client.url_get(url)