Segment: Allow for setting multicast in advanced_config
This change enables specifying multicast in Segment's advanced_config attribute. Upon update, the attribute is replaced. It is up to the caller to make sure other components such as address_pool_paths are not overwritten. Change-Id: I738daa6243772006b69e6149b42de9451befa7e5
This commit is contained in:
parent
d0b20761cd
commit
aa25bd32fd
@ -4503,7 +4503,7 @@ class TestPolicySegment(NsxPolicyLibTestCase):
|
||||
|
||||
def _test_create(self, tier1_id=None, tier0_id=None, mdproxy=None,
|
||||
dhcp_server=None, admin_state=None,
|
||||
ip_pool_id='external-ip-pool', ls_id=None,
|
||||
ip_pool_id='external-ip-pool', multicast=None, ls_id=None,
|
||||
unique_id=None, tz_id=None, ep_id=None, overlay_id=None):
|
||||
name = 'test'
|
||||
description = 'desc'
|
||||
@ -4512,6 +4512,8 @@ class TestPolicySegment(NsxPolicyLibTestCase):
|
||||
'subnets': subnets,
|
||||
'ip_pool_id': ip_pool_id,
|
||||
'tenant': TEST_TENANT}
|
||||
if multicast:
|
||||
kwargs['multicast'] = multicast
|
||||
if tier1_id:
|
||||
kwargs['tier1_id'] = tier1_id
|
||||
|
||||
@ -4559,6 +4561,8 @@ class TestPolicySegment(NsxPolicyLibTestCase):
|
||||
ip_pool_path = ip_pool_def.get_resource_full_path()
|
||||
expected_advanced_config = {
|
||||
'address_pool_paths': [ip_pool_path]}
|
||||
if multicast is not None:
|
||||
expected_advanced_config.update({'multicast': multicast})
|
||||
self.assertEqual(expected_def.get_obj_dict()['advanced_config'],
|
||||
expected_advanced_config)
|
||||
|
||||
@ -4603,6 +4607,12 @@ class TestPolicySegment(NsxPolicyLibTestCase):
|
||||
def test_create_with_overlay_id(self):
|
||||
self._test_create(overlay_id=100)
|
||||
|
||||
def test_create_with_multicast_and_no_ip_pool(self):
|
||||
self._test_create(tier1_id='111', ip_pool_id=None, multicast=True)
|
||||
|
||||
def test_create_with_multicast_and_ip_pool(self):
|
||||
self._test_create(tier1_id='111', ip_pool_id='xxx', multicast=True)
|
||||
|
||||
def test_delete(self):
|
||||
segment_id = '111'
|
||||
with mock.patch.object(self.policy_api, "delete") as api_call:
|
||||
@ -4648,6 +4658,25 @@ class TestPolicySegment(NsxPolicyLibTestCase):
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(update_call, expected_def)
|
||||
|
||||
def test_update_with_multicast(self):
|
||||
# Test and update call which sets advanced_config
|
||||
segment_id = '111'
|
||||
admin_state = False
|
||||
with self.mock_get(segment_id, 'xxx'), \
|
||||
self.mock_create_update() as update_call:
|
||||
|
||||
self.resourceApi.update(segment_id,
|
||||
admin_state=admin_state,
|
||||
multicast=False,
|
||||
tenant=TEST_TENANT)
|
||||
expected_def = core_defs.SegmentDef(
|
||||
nsx_version=nsxlib_testcase.LATEST_VERSION,
|
||||
segment_id=segment_id,
|
||||
multicast=False,
|
||||
admin_state=admin_state,
|
||||
tenant=TEST_TENANT)
|
||||
self.assert_called_with_def(update_call, expected_def)
|
||||
|
||||
def test_remove_connectivity_and_subnets(self):
|
||||
segment_id = '111'
|
||||
with mock.patch.object(self.policy_api, "get",
|
||||
|
@ -938,12 +938,15 @@ class BaseSegmentDef(ResourceDef):
|
||||
for subnet in self.get_attr('subnets')]
|
||||
self._set_attr_if_specified(body, 'subnets', value=subnets)
|
||||
|
||||
adv_cfg = {}
|
||||
if self.has_attr('ip_pool_id'):
|
||||
ip_pool_id = self.get_attr('ip_pool_id')
|
||||
adv_cfg = self._get_adv_config(ip_pool_id)
|
||||
self._set_attr_if_specified(body, 'ip_pool_id',
|
||||
body_attr='advanced_config',
|
||||
value=adv_cfg)
|
||||
adv_cfg.update(self._get_adv_config_ip_pool(ip_pool_id))
|
||||
if self.has_attr('multicast'):
|
||||
adv_cfg['multicast'] = self.get_attr('multicast')
|
||||
if adv_cfg:
|
||||
body['advanced_config'] = adv_cfg
|
||||
|
||||
self._set_attrs_if_specified(
|
||||
body, ['domain_name', 'vlan_ids', 'ls_id'])
|
||||
return body
|
||||
@ -952,7 +955,7 @@ class BaseSegmentDef(ResourceDef):
|
||||
def resource_type():
|
||||
return 'Segment'
|
||||
|
||||
def _get_adv_config(self, ip_pool_id):
|
||||
def _get_adv_config_ip_pool(self, ip_pool_id):
|
||||
if ip_pool_id is None:
|
||||
return {'address_pool_paths': []}
|
||||
ip_pool_def = IpPoolDef(ip_pool_id=ip_pool_id)
|
||||
|
@ -2259,6 +2259,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
||||
vlan_ids=IGNORE,
|
||||
transport_zone_id=IGNORE,
|
||||
ip_pool_id=IGNORE,
|
||||
multicast=IGNORE,
|
||||
metadata_proxy_id=IGNORE,
|
||||
dhcp_server_config_id=IGNORE,
|
||||
admin_state=IGNORE,
|
||||
@ -2286,6 +2287,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
||||
vlan_ids=vlan_ids,
|
||||
transport_zone_id=transport_zone_id,
|
||||
ip_pool_id=ip_pool_id,
|
||||
multicast=multicast,
|
||||
metadata_proxy_id=metadata_proxy_id,
|
||||
dhcp_server_config_id=dhcp_server_config_id,
|
||||
admin_state=admin_state,
|
||||
@ -2323,10 +2325,14 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
||||
def update(self, segment_id, name=IGNORE, description=IGNORE,
|
||||
tier1_id=IGNORE, tier0_id=IGNORE, subnets=IGNORE,
|
||||
dns_domain_name=IGNORE,
|
||||
vlan_ids=IGNORE, metadata_proxy_id=IGNORE,
|
||||
vlan_ids=IGNORE, multicast=IGNORE, metadata_proxy_id=IGNORE,
|
||||
dhcp_server_config_id=IGNORE, admin_state=IGNORE,
|
||||
tags=IGNORE, tenant=constants.POLICY_INFRA_TENANT):
|
||||
|
||||
# NOTE: Setting multicast upon update will reset any other advanced
|
||||
# config attribute that might have been set previously
|
||||
# TODO(sorlando): Regardless of patch strategy always fetch advanced
|
||||
# config and merge before updating
|
||||
self._update(segment_id=segment_id,
|
||||
name=name,
|
||||
description=description,
|
||||
@ -2335,6 +2341,7 @@ class NsxPolicySegmentApi(NsxPolicyResourceBase):
|
||||
subnets=subnets,
|
||||
dns_domain_name=dns_domain_name,
|
||||
vlan_ids=vlan_ids,
|
||||
multicast=multicast,
|
||||
metadata_proxy_id=metadata_proxy_id,
|
||||
dhcp_server_config_id=dhcp_server_config_id,
|
||||
admin_state=admin_state,
|
||||
|
Loading…
Reference in New Issue
Block a user