From e2d38173ce9482843f93ee48ba27781219b07351 Mon Sep 17 00:00:00 2001 From: asarfaty Date: Sun, 1 Dec 2019 10:58:55 +0200 Subject: [PATCH] Add search index out of sync exception Search actions will retry on this exception. Change-Id: I967f140b45e43d5aa64d5a9a2148e6a9e84f100f --- vmware_nsxlib/v3/client.py | 1 + vmware_nsxlib/v3/exceptions.py | 4 ++++ vmware_nsxlib/v3/lib.py | 6 +++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/vmware_nsxlib/v3/client.py b/vmware_nsxlib/v3/client.py index 85443d4c..e1a1e05e 100644 --- a/vmware_nsxlib/v3/client.py +++ b/vmware_nsxlib/v3/client.py @@ -37,6 +37,7 @@ def http_error_to_exception(status_code, error_code): requests.codes.BAD_REQUEST: {'60508': exceptions.NsxIndexingInProgress, '60514': exceptions.NsxSearchTimeout, + '60515': exceptions.NsxSearchOutOfSync, '8327': exceptions.NsxOverlapVlan, '500045': exceptions.NsxPendingDelete, '500030': exceptions.ResourceInUse, diff --git a/vmware_nsxlib/v3/exceptions.py b/vmware_nsxlib/v3/exceptions.py index 085f83ad..d66fc753 100644 --- a/vmware_nsxlib/v3/exceptions.py +++ b/vmware_nsxlib/v3/exceptions.py @@ -197,6 +197,10 @@ class NsxSearchTimeout(NsxSearchError): "or running low on resources") +class NsxSearchOutOfSync(NsxSearchError): + message = _("Index is currently out of sync") + + 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 3d4c8d35..85eec8f6 100644 --- a/vmware_nsxlib/v3/lib.py +++ b/vmware_nsxlib/v3/lib.py @@ -152,7 +152,7 @@ class NsxLibBase(object): url = self._add_pagination_parameters("search?query=%s" % query, cursor, page_size) - # Retry the search on case of error + # Retry the search in case of error @utils.retry_upon_exception(exceptions.NsxSearchError, max_attempts=self.client.max_attempts) def do_search(url): @@ -189,8 +189,8 @@ class NsxLibBase(object): url = self._add_pagination_parameters("search?query=%s" % query, cursor, page_size) - # Retry the search on case of error - @utils.retry_upon_exception(exceptions.NsxIndexingInProgress, + # Retry the search in case of error + @utils.retry_upon_exception(exceptions.NsxSearchError, max_attempts=self.client.max_attempts) def do_search(url): return self.client.url_get(url)