Merge "Fix T1 partial update"

This commit is contained in:
Zuul 2019-04-20 07:22:27 +00:00 committed by Gerrit Code Review
commit d6a2421e04
2 changed files with 36 additions and 31 deletions

View File

@ -2514,7 +2514,7 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
obj_id = '111'
rtr_name = 'rtr111'
ndra_profile_id = 'test'
ndra_profile_path = '/infra/ipv6-ndra-profile/%s' % ndra_profile_id
ndra_profile_path = '/infra/ipv6-ndra-profiles/%s' % ndra_profile_id
get_result = {'id': obj_id,
'display_name': rtr_name,
'enable_standby_relocation': False,
@ -2760,7 +2760,8 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
with mock.patch.object(self.policy_api,
"get",
return_value={'id': tier1_id,
'display_name': 'tier1name'}),\
'display_name': 'tier1name',
'resource_type': 'Tier1'}),\
mock.patch.object(self.policy_api,
'create_or_update') as api_call:
self.resourceApi.add_advertisement_rule(

View File

@ -890,12 +890,18 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
enable_standby_relocation=IGNORE,
disable_firewall=IGNORE,
ipv6_ndra_profile_id=IGNORE,
tenant=constants.POLICY_INFRA_TENANT):
route_advertisement=IGNORE,
route_advertisement_rules=IGNORE,
tenant=constants.POLICY_INFRA_TENANT,
current_body=None):
# Note(asarfaty): L2/L3 PATCH APIs don't support partial updates yet
# TODO(asarfaty): Remove this when supported
if (name == IGNORE or enable_standby_relocation == IGNORE or
ipv6_ndra_profile_id == IGNORE):
current_body = self.get(tier1_id, tenant=tenant)
ipv6_ndra_profile_id == IGNORE or tags == IGNORE or
current_body):
if not current_body:
current_body = self.get(tier1_id, tenant=tenant)
if name == IGNORE:
name = current_body.get('display_name', IGNORE)
if enable_standby_relocation == IGNORE:
@ -904,6 +910,15 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
if ipv6_ndra_profile_id == IGNORE:
ipv6_ndra_profile_id = self._get_ipv6_profile_from_dict(
current_body)
if route_advertisement_rules == IGNORE:
route_advertisement_rules = current_body.get(
'route_advertisement_rules', IGNORE)
if route_advertisement == IGNORE and current_body.get(
'route_advertisement_types'):
route_advertisement = self.entry_def.get_route_adv(
current_body)
if tags == IGNORE:
tags = current_body.get('tags', IGNORE)
self._update(tier1_id=tier1_id,
name=name,
@ -915,6 +930,8 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
enable_standby_relocation=enable_standby_relocation,
disable_firewall=disable_firewall,
ipv6_ndra_profile_id=ipv6_ndra_profile_id,
route_advertisement=route_advertisement,
route_advertisement_rules=route_advertisement_rules,
tags=tags,
tenant=tenant)
@ -926,7 +943,7 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
for profile in ipv6_profiles:
tokens = profile.split('/')
if len(tokens) > 3 and tokens[2] == 'ipv6-ndra-profile':
if len(tokens) > 3 and tokens[2] == 'ipv6-ndra-profiles':
return tokens[3]
def update_route_advertisement(
@ -946,20 +963,10 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
lb_vip=lb_vip,
lb_snat=lb_snat)
# Note(asarfaty) keep tier1 name and enable_standby_relocation as
# well, as the current nsx implementation resets name to the ID and
# enable_standby_relocation to false and ndra profile.
# TODO(asarfaty): Remove this when supported
ndra_profile_id = self._get_ipv6_profile_from_dict(tier1_dict)
tier1_def = self._init_def(tier1_id=tier1_id,
name=tier1_dict.get('display_name'),
enable_standby_relocation=tier1_dict.get(
'enable_standby_relocation'),
route_advertisement=route_adv,
ipv6_ndra_profile_id=ndra_profile_id,
tenant=tenant)
self.policy_api.create_or_update(tier1_def)
self.update(tier1_id,
route_advertisement=route_adv,
tenant=tenant,
current_body=tier1_dict)
def add_advertisement_rule(
self, tier1_id, name, action=None, prefix_operator=None,
@ -974,11 +981,10 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
route_advertisement_types=route_advertisement_types,
subnets=subnets)
adv_rules.append(adv_rule)
tier1_def = self.entry_def(tier1_id=tier1_id,
name=tier1_dict.get('display_name'),
route_advertisement_rules=adv_rules,
tenant=tenant)
self.policy_api.create_or_update(tier1_def)
self.update(tier1_id,
route_advertisement_rules=adv_rules,
tenant=tenant,
current_body=tier1_dict)
def remove_advertisement_rule(self, tier1_id, name,
tenant=constants.POLICY_INFRA_TENANT):
@ -986,12 +992,10 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
adv_rules = tier1_dict.get('route_advertisement_rules', [])
updated_adv_rules = [r for r in adv_rules if r.get('name') != name]
if updated_adv_rules != adv_rules:
tier1_def = self.entry_def(
tier1_id=tier1_id,
name=tier1_dict.get('display_name'),
route_advertisement_rules=updated_adv_rules,
tenant=tenant)
self.policy_api.create_or_update(tier1_def)
self.update(tier1_id,
route_advertisement_rules=updated_adv_rules,
tenant=tenant,
current_body=tier1_dict)
def _locale_service_id(self, tier1_id):
# Supporting only a single locale-service per router for now