From 5a4ab83eec6a397ff511eefb18fa1b61bc0cf803 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Wed, 27 Mar 2019 08:46:20 +0200 Subject: [PATCH] Add search error code & retry Retry V3 search requests in case of timeout error as well. Change-Id: I9fde4b6319d31719e09246f1432b58b27097e16b --- vmware_nsxlib/v3/client.py | 1 + vmware_nsxlib/v3/exceptions.py | 11 ++++++++++- vmware_nsxlib/v3/lib.py | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/vmware_nsxlib/v3/client.py b/vmware_nsxlib/v3/client.py index 72b559f8..2c5ea5a5 100644 --- a/vmware_nsxlib/v3/client.py +++ b/vmware_nsxlib/v3/client.py @@ -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, diff --git a/vmware_nsxlib/v3/exceptions.py b/vmware_nsxlib/v3/exceptions.py index f2beab9e..3675c60f 100644 --- a/vmware_nsxlib/v3/exceptions.py +++ b/vmware_nsxlib/v3/exceptions.py @@ -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 " diff --git a/vmware_nsxlib/v3/lib.py b/vmware_nsxlib/v3/lib.py index cebe3794..4e64be10 100644 --- a/vmware_nsxlib/v3/lib.py +++ b/vmware_nsxlib/v3/lib.py @@ -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)