From f787f7cf3e66b798785a6700daf795ad8d6d8c90 Mon Sep 17 00:00:00 2001 From: asarfaty Date: Sun, 23 Aug 2020 08:13:42 +0200 Subject: [PATCH] Add stale revision retry on policy update calls (using PATCH) Change-Id: Ic6c4a8dc1af50818012df48d77314a1e5f1737ac --- vmware_nsxlib/v3/policy/core_resources.py | 30 ++++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/vmware_nsxlib/v3/policy/core_resources.py b/vmware_nsxlib/v3/policy/core_resources.py index 85140e25..2d747ae4 100644 --- a/vmware_nsxlib/v3/policy/core_resources.py +++ b/vmware_nsxlib/v3/policy/core_resources.py @@ -143,19 +143,25 @@ class NsxPolicyResourceBase(object, metaclass=abc.ABCMeta): def _update(self, allow_partial_updates=True, force=False, **kwargs): """Helper for update function - ignore attrs without explicit value""" - if (allow_partial_updates and - self.policy_api.partial_updates_supported()): - policy_def = self._init_def(**kwargs) - partial_updates = True - else: - policy_def = self._get_and_update_def(**kwargs) - partial_updates = False + @utils.retry_upon_exception( + exceptions.StaleRevision, + max_attempts=self.policy_api.client.max_attempts) + def _do_update_with_retry(): + if (allow_partial_updates and + self.policy_api.partial_updates_supported()): + policy_def = self._init_def(**kwargs) + partial_updates = True + else: + policy_def = self._get_and_update_def(**kwargs) + partial_updates = False - if policy_def.bodyless(): - # Nothing to update - only keys provided in kwargs - return - self.policy_api.create_or_update( - policy_def, partial_updates=partial_updates, force=force) + if policy_def.bodyless(): + # Nothing to update - only keys provided in kwargs + return + self.policy_api.create_or_update( + policy_def, partial_updates=partial_updates, force=force) + + return _do_update_with_retry() @staticmethod def _init_obj_uuid(obj_uuid):