From 03fd42824e49253995c276c4ac2860923f367b95 Mon Sep 17 00:00:00 2001 From: asarfaty Date: Sun, 2 Feb 2020 14:05:10 +0200 Subject: [PATCH] Set default ipv6 ndra profile instead of empty value Change-Id: I2d61ce9443ea0ee407efec286682cc3267fadf34 --- .../tests/unit/v3/policy/test_api.py | 39 ++++++++++++++++++- .../tests/unit/v3/policy/test_resources.py | 38 ++++++++++++++++++ vmware_nsxlib/v3/policy/core_defs.py | 24 ++++++++++-- 3 files changed, 95 insertions(+), 6 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_api.py b/vmware_nsxlib/tests/unit/v3/policy/test_api.py index 6879be43..ea3786a5 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_api.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_api.py @@ -366,17 +366,52 @@ class TestPolicyTier1(policy_testcase.TestPolicyApi): nat=True, lb_vip=False, lb_snat=False) + ipv6_ndra_profile_id = '111' tier1_def = policy.Tier1Def( tier1_id=tier1_id, name=name, description=description, route_advertisement=route_adv, - tier0=tier0_id) + tier0=tier0_id, + ipv6_ndra_profile_id=ipv6_ndra_profile_id) expected_data = {"id": "%s" % tier1_id, "resource_type": "Tier1", "description": "%s" % description, "display_name": "%s" % name, "tier0_path": "/infra/tier-0s/%s" % tier0_id, - "route_advertisement_types": route_adv.get_obj_dict()} + "route_advertisement_types": route_adv.get_obj_dict(), + "ipv6_profile_paths": ["/infra/ipv6-ndra-profiles/" + "%s" % ipv6_ndra_profile_id]} + self.policy_api.create_or_update(tier1_def) + tier1_path = tier1_def.get_resource_path() + self.assert_json_call('PATCH', self.client, + tier1_path, + data=expected_data) + + def test_create_no_ipv6_profile(self): + name = 'test' + description = 'desc' + tier0_id = '000' + tier1_id = '111' + route_adv = policy.RouteAdvertisement(static_routes=True, + subnets=True, + nat=True, + lb_vip=False, + lb_snat=False) + ipv6_ndra_profile_id = None + tier1_def = policy.Tier1Def( + tier1_id=tier1_id, + name=name, description=description, + route_advertisement=route_adv, + tier0=tier0_id, + ipv6_ndra_profile_id=ipv6_ndra_profile_id) + expected_data = {"id": "%s" % tier1_id, + "resource_type": "Tier1", + "description": "%s" % description, + "display_name": "%s" % name, + "tier0_path": "/infra/tier-0s/%s" % tier0_id, + "route_advertisement_types": route_adv.get_obj_dict(), + "ipv6_profile_paths": ["/infra/ipv6-ndra-profiles/" + "default"]} self.policy_api.create_or_update(tier1_def) tier1_path = tier1_def.get_resource_path() self.assert_json_call('PATCH', self.client, diff --git a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py index decd483d..8120c26e 100644 --- a/vmware_nsxlib/tests/unit/v3/policy/test_resources.py +++ b/vmware_nsxlib/tests/unit/v3/policy/test_resources.py @@ -2561,6 +2561,7 @@ class TestPolicyTier1(NsxPolicyLibTestCase): route_adv = self.resourceApi.build_route_advertisement( lb_vip=True, lb_snat=True) + ipv6_profile_id = '222' with mock.patch.object(self.policy_api, "create_or_update") as api_call: @@ -2570,6 +2571,7 @@ class TestPolicyTier1(NsxPolicyLibTestCase): force_whitelisting=True, route_advertisement=route_adv, pool_allocation=pool_alloc_type, + ipv6_ndra_profile_id=ipv6_profile_id, tenant=TEST_TENANT) expected_def = core_defs.Tier1Def( @@ -2582,6 +2584,42 @@ class TestPolicyTier1(NsxPolicyLibTestCase): failover_mode=constants.NON_PREEMPTIVE, route_advertisement=route_adv, pool_allocation=pool_alloc_type, + ipv6_ndra_profile_id=ipv6_profile_id, + tenant=TEST_TENANT) + self.assert_called_with_def(api_call, expected_def) + self.assertIsNotNone(result) + + def test_create_no_ipv6_profile(self): + name = 'test' + description = 'desc' + tier0_id = '111' + pool_alloc_type = 'LB_SMALL' + route_adv = self.resourceApi.build_route_advertisement( + lb_vip=True, + lb_snat=True) + + with mock.patch.object(self.policy_api, + "create_or_update") as api_call: + result = self.resourceApi.create_or_overwrite( + name, description=description, + tier0=tier0_id, + force_whitelisting=True, + route_advertisement=route_adv, + pool_allocation=pool_alloc_type, + ipv6_ndra_profile_id=None, + tenant=TEST_TENANT) + + expected_def = core_defs.Tier1Def( + nsx_version=self.policy_lib.get_version(), + tier1_id=mock.ANY, + name=name, + description=description, + tier0=tier0_id, + force_whitelisting=True, + failover_mode=constants.NON_PREEMPTIVE, + route_advertisement=route_adv, + pool_allocation=pool_alloc_type, + ipv6_ndra_profile_id=None, tenant=TEST_TENANT) self.assert_called_with_def(api_call, expected_def) self.assertIsNotNone(result) diff --git a/vmware_nsxlib/v3/policy/core_defs.py b/vmware_nsxlib/v3/policy/core_defs.py index 4ed685c9..0b35b10c 100644 --- a/vmware_nsxlib/v3/policy/core_defs.py +++ b/vmware_nsxlib/v3/policy/core_defs.py @@ -377,13 +377,19 @@ class RouterDef(ResourceDef): value=paths) if self.has_attr('ipv6_ndra_profile_id'): - paths = "" if self.get_attr('ipv6_ndra_profile_id'): ndra_profile = Ipv6NdraProfileDef( profile_id=self.get_attr('ipv6_ndra_profile_id'), tenant=self.get_tenant()) - paths = [ndra_profile.get_resource_full_path()] + else: + # Set it to the default profile + # This will allow removing the old profile, + # as the NSX does not support empty value. + ndra_profile = Ipv6NdraProfileDef( + profile_id=Ipv6NdraProfileDef.default_profile(), + tenant=self.get_tenant()) + paths = [ndra_profile.get_resource_full_path()] self._set_attr_if_specified(body, 'ipv6_ndra_profile_id', body_attr='ipv6_profile_paths', value=paths) @@ -594,13 +600,19 @@ class Tier1InterfaceDef(ResourceDef): value=path) if self.has_attr('ipv6_ndra_profile_id'): - paths = "" if self.get_attr('ipv6_ndra_profile_id'): ndra_profile = Ipv6NdraProfileDef( profile_id=self.get_attr('ipv6_ndra_profile_id'), tenant=self.get_tenant()) - paths = [ndra_profile.get_resource_full_path()] + else: + # Set it to the default profile + # This will allow removing the old profile, + # as the NSX does not support empty value. + ndra_profile = Ipv6NdraProfileDef( + profile_id=Ipv6NdraProfileDef.default_profile(), + tenant=self.get_tenant()) + paths = [ndra_profile.get_resource_full_path()] self._set_attr_if_specified(body, 'ipv6_ndra_profile_id', body_attr='ipv6_profile_paths', value=paths) @@ -2109,6 +2121,10 @@ class Ipv6NdraProfileDef(ResourceDef): def resource_type(): return 'Ipv6NdraProfile' + @staticmethod + def default_profile(): + return 'default' + def path_defs(self): return (TenantDef,)