Merge "Fix ndra profile in partial T1 update"

This commit is contained in:
Zuul
2019-04-14 11:53:00 +00:00
committed by Gerrit Code Review
2 changed files with 49 additions and 17 deletions

View File

@@ -2322,8 +2322,9 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
obj_id = '111'
name = 'new name'
tier0 = 'tier0'
with mock.patch.object(self.policy_api,
"create_or_update") as update_call:
with mock.patch.object(self.policy_api, "get", return_value={}),\
mock.patch.object(self.policy_api,
"create_or_update") as update_call:
self.resourceApi.update(obj_id,
name=name, tier0=tier0,
enable_standby_relocation=False,
@@ -2339,8 +2340,10 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
def test_update_ignore_tier0(self):
obj_id = '111'
name = 'new name'
with mock.patch.object(self.policy_api,
"create_or_update") as update_call:
with mock.patch.object(self.policy_api, "get",
return_value={}),\
mock.patch.object(self.policy_api,
"create_or_update") as update_call:
self.resourceApi.update(obj_id,
name=name,
enable_standby_relocation=False,
@@ -2358,8 +2361,10 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
obj_id = '111'
name = 'new name'
description = 'abc'
with mock.patch.object(self.policy_api,
"create_or_update") as update_call:
with mock.patch.object(self.policy_api, "get",
return_value={}),\
mock.patch.object(self.policy_api,
"create_or_update") as update_call:
self.resourceApi.update(obj_id,
name=name,
description=description,
@@ -2381,9 +2386,12 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
def test_update_route_adv(self):
obj_id = '111'
rtr_name = 'rtr111'
ndra_profile_id = 'test'
ndra_profile_path = '/infra/ipv6-ndra-profile/%s' % ndra_profile_id
get_result = {'id': obj_id,
'display_name': rtr_name,
'enable_standby_relocation': False,
'ipv6_profile_paths': [ndra_profile_path],
'route_advertisement_types': ['TIER1_NAT',
'TIER1_LB_VIP']}
with mock.patch.object(self.policy_api, "get",
@@ -2400,11 +2408,14 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
new_adv = self.resourceApi.build_route_advertisement(
nat=True, static_routes=True, lb_snat=True)
expected_def = core_defs.Tier1Def(tier1_id=obj_id,
name=rtr_name,
enable_standby_relocation=False,
route_advertisement=new_adv,
tenant=TEST_TENANT)
expected_def = core_defs.Tier1Def(
tier1_id=obj_id,
name=rtr_name,
enable_standby_relocation=False,
route_advertisement=new_adv,
ipv6_ndra_profile_id=ndra_profile_id,
tenant=TEST_TENANT)
self.assert_called_with_def(
update_call, expected_def)
@@ -2412,8 +2423,10 @@ class TestPolicyTier1(NsxPolicyLibTestCase):
obj_id = '111'
name = 'new name'
tier0 = 'tier0'
with mock.patch.object(self.policy_api,
"create_or_update") as update_call:
with mock.patch.object(self.policy_api, "get",
return_value={}),\
mock.patch.object(self.policy_api,
"create_or_update") as update_call:
self.resourceApi.update(obj_id,
name=name, tier0=tier0,
enable_standby_relocation=True,

View File

@@ -867,13 +867,18 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
tenant=constants.POLICY_INFRA_TENANT):
# 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:
if (name == IGNORE or enable_standby_relocation == IGNORE or
ipv6_ndra_profile_id == IGNORE):
current_body = self.get(tier1_id, tenant=tenant)
if name == IGNORE:
name = current_body.get('display_name', IGNORE)
else:
if enable_standby_relocation == IGNORE:
enable_standby_relocation = current_body.get(
'enable_standby_relocation', IGNORE)
if ipv6_ndra_profile_id == IGNORE:
ipv6_ndra_profile_id = self._get_ipv6_profile_from_dict(
current_body)
self._update(tier1_id=tier1_id,
name=name,
description=description,
@@ -887,6 +892,17 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
tags=tags,
tenant=tenant)
# TODO(annak): remove this func when partial update is supported
def _get_ipv6_profile_from_dict(self, obj_dict):
ipv6_profiles = obj_dict.get('ipv6_profile_paths', [])
if not ipv6_profiles:
return IGNORE
for profile in ipv6_profiles:
tokens = profile.split('/')
if len(tokens) > 3 and tokens[2] == 'ipv6-ndra-profile':
return tokens[3]
def update_route_advertisement(
self, tier1_id,
static_routes=None,
@@ -906,13 +922,16 @@ class NsxPolicyTier1Api(NsxPolicyResourceBase):
# 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.
# enable_standby_relocation to false and ndra profile.
# TODO(asarfaty): Remove this when supported
tier1_def = self.entry_def(tier1_id=tier1_id,
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)