Ensure retry on stale rule update or deletion

Ensure that we do retry if the NSX returns a stale resource.

Change-Id: Ia4324900365d9749cb470ad7bcf45995349ce1d1
This commit is contained in:
Gary Kotton 2017-08-26 23:19:27 -07:00
parent 2a68ede0c0
commit de76f60c55
1 changed files with 54 additions and 29 deletions

View File

@ -327,31 +327,41 @@ class NsxLibFirewallSection(utils.NsxLibApiBase):
applied_tos, tags, applied_tos, tags,
operation=consts.FW_INSERT_BOTTOM, operation=consts.FW_INSERT_BOTTOM,
other_section=None): other_section=None):
resource = 'firewall/sections?operation=%s' % operation @utils.retry_upon_exception(
body = self._build(display_name, description, exceptions.StaleRevision,
applied_tos, tags) max_attempts=self.nsxlib_config.max_attempts)
if other_section: def _create_empty():
resource += '&id=%s' % other_section resource = 'firewall/sections?operation=%s' % operation
return self.client.create(resource, body) body = self._build(display_name, description,
applied_tos, tags)
if other_section:
resource += '&id=%s' % other_section
return self.client.create(resource, body)
return _create_empty()
def create_with_rules(self, display_name, description, applied_tos=None, def create_with_rules(self, display_name, description, applied_tos=None,
tags=None, operation=consts.FW_INSERT_BOTTOM, tags=None, operation=consts.FW_INSERT_BOTTOM,
other_section=None, rules=None): other_section=None, rules=None):
resource = 'firewall/sections?operation=%s' % operation @utils.retry_upon_exception(
body = { exceptions.StaleRevision,
'display_name': display_name, max_attempts=self.nsxlib_config.max_attempts)
'description': description, def _create_with_rules():
'stateful': True, resource = 'firewall/sections?operation=%s' % operation
'section_type': consts.FW_SECTION_LAYER3, body = {
'applied_tos': applied_tos or [], 'display_name': display_name,
'rules': rules or [], 'description': description,
'tags': tags or [] 'stateful': True,
} 'section_type': consts.FW_SECTION_LAYER3,
if rules: 'applied_tos': applied_tos or [],
resource += '&action=create_with_rules' 'rules': rules or [],
if other_section: 'tags': tags or []
resource += '&id=%s' % other_section }
return self.client.create(resource, body) if rules:
resource += '&action=create_with_rules'
if other_section:
resource += '&id=%s' % other_section
return self.client.create(resource, body)
return _create_with_rules()
def update(self, section_id, display_name=None, description=None, def update(self, section_id, display_name=None, description=None,
applied_tos=None, rules=None, tags_update=None, force=False): applied_tos=None, rules=None, tags_update=None, force=False):
@ -455,18 +465,33 @@ class NsxLibFirewallSection(utils.NsxLibApiBase):
return rule_dict return rule_dict
def add_rule(self, rule, section_id): def add_rule(self, rule, section_id):
resource = 'firewall/sections/%s/rules' % section_id @utils.retry_upon_exception(
params = '?operation=insert_bottom' exceptions.StaleRevision,
return self.client.create(resource + params, rule) max_attempts=self.nsxlib_config.max_attempts)
def _add_rule():
resource = 'firewall/sections/%s/rules' % section_id
params = '?operation=insert_bottom'
return self.client.create(resource + params, rule)
return _add_rule()
def add_rules(self, rules, section_id): def add_rules(self, rules, section_id):
resource = 'firewall/sections/%s/rules' % section_id @utils.retry_upon_exception(
params = '?action=create_multiple&operation=insert_bottom' exceptions.StaleRevision,
return self.client.create(resource + params, {'rules': rules}) max_attempts=self.nsxlib_config.max_attempts)
def _add_rules():
resource = 'firewall/sections/%s/rules' % section_id
params = '?action=create_multiple&operation=insert_bottom'
return self.client.create(resource + params, {'rules': rules})
return _add_rules()
def delete_rule(self, section_id, rule_id): def delete_rule(self, section_id, rule_id):
resource = 'firewall/sections/%s/rules/%s' % (section_id, rule_id) @utils.retry_upon_exception(
return self.client.delete(resource) exceptions.StaleRevision,
max_attempts=self.nsxlib_config.max_attempts)
def _delete_rule():
resource = 'firewall/sections/%s/rules/%s' % (section_id, rule_id)
return self.client.delete(resource)
return _delete_rule()
def get_rules(self, section_id): def get_rules(self, section_id):
resource = 'firewall/sections/%s/rules' % section_id resource = 'firewall/sections/%s/rules' % section_id