NSX|P: Use policy search for getting neutron net id

retruning the neutron net id by the logical switch id using the policy
search api, instead of passthrough api.

Change-Id: I30d921157191d880e2bcf74cf8b602de8e5684dc
This commit is contained in:
asarfaty 2019-11-27 11:37:31 +02:00 committed by Adit Sarfaty
parent 1fdc46e140
commit 496cdad624
2 changed files with 10 additions and 14 deletions

View File

@ -3001,17 +3001,13 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
for this, and cache the results.
"""
if lswitch_id not in NET_NSX_2_NEUTRON_ID_CACHE:
# Go to the nsx using passthrough api to get the neutron id
if not cfg.CONF.nsx_p.allow_passthrough:
LOG.warning("Cannot get neutron id for ls %s without "
"passthrough api", lswitch_id)
segments_path = self.nsxpolicy.search_resource_by_realized_id(
lswitch_id, "RealizedLogicalSwitch")
if not segments_path or len(segments_path) != 1:
LOG.warning("Could not find policy segment with realized id "
"%s", lswitch_id)
return []
ls = self.nsxlib.logical_switch.get(lswitch_id)
neutron_id = None
for tag in ls.get('tags', []):
if tag['scope'] == 'os-neutron-net-id':
neutron_id = tag['tag']
break
neutron_id = p_utils.path_to_id(segments_path[0])
if neutron_id:
# Cache the result
NET_NSX_2_NEUTRON_ID_CACHE[lswitch_id] = neutron_id

View File

@ -972,12 +972,12 @@ class NsxNativeMetadataTestCase(test_plugin.NsxPPluginTestCaseMixin):
set([s1['subnet']['id'], s2['subnet']['id']]))
lswitch_id = 'dummy'
neutron_id = n1['network']['id']
nsx_tag = {'tag': neutron_id, 'scope': 'os-neutron-net-id'}
segment_path = '/infra/segments/%s' % neutron_id
# Get only the subnets associated with a particular advanced
# service provider (i.e. logical switch).
with mock.patch('vmware_nsxlib.v3.core_resources.'
'NsxLibLogicalSwitch.get',
return_value={'tags': [nsx_tag]}):
with mock.patch('vmware_nsxlib.v3.policy.NsxPolicyLib.'
'search_resource_by_realized_id',
return_value=[segment_path]):
subnets = self._list('subnets', query_params='%s=%s' %
(as_providers.ADV_SERVICE_PROVIDERS,
lswitch_id))['subnets']