Merge "Add search error code & retry"

This commit is contained in:
Zuul
2019-03-31 05:01:50 +00:00
committed by Gerrit Code Review
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)