NSX|V3: enable VLAN transparent to be configured with VLAN

The plugin will enforce that a VLAN ID should not be configured
with the transparent flag.

Change-Id: I9310e2de62346b805514fdd5cd3507b245e8e0cc
This commit is contained in:
Gary Kotton 2018-01-31 20:44:32 +02:00
parent 9ab1f68179
commit bfce2c50b4
2 changed files with 16 additions and 15 deletions

View File

@ -773,6 +773,11 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
if not validators.is_attr_set(vlan_id): if not validators.is_attr_set(vlan_id):
vlan_id = None vlan_id = None
if vlan_id and transparent_vlan:
err_msg = (_("Segmentation ID cannot be set with transparent "
"vlan!"))
raise n_exc.InvalidInput(error_message=err_msg)
err_msg = None err_msg = None
net_type = network_data.get(pnet.NETWORK_TYPE) net_type = network_data.get(pnet.NETWORK_TYPE)
nsxlib_tz = self.nsxlib.transport_zone nsxlib_tz = self.nsxlib.transport_zone
@ -785,11 +790,13 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
"%s network type") % "%s network type") %
utils.NsxV3NetworkTypes.FLAT) utils.NsxV3NetworkTypes.FLAT)
else: else:
# Set VLAN id to 0 for flat networks if not transparent_vlan:
vlan_id = '0' # Set VLAN id to 0 for flat networks
vlan_id = '0'
if physical_net is None: if physical_net is None:
physical_net = az._default_vlan_tz_uuid physical_net = az._default_vlan_tz_uuid
elif net_type == utils.NsxV3NetworkTypes.VLAN: elif (net_type == utils.NsxV3NetworkTypes.VLAN and
not transparent_vlan):
# Use default VLAN transport zone if physical network not given # Use default VLAN transport zone if physical network not given
if physical_net is None: if physical_net is None:
physical_net = az._default_vlan_tz_uuid physical_net = az._default_vlan_tz_uuid
@ -814,6 +821,11 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
if bindings: if bindings:
raise n_exc.VlanIdInUse( raise n_exc.VlanIdInUse(
vlan_id=vlan_id, physical_network=physical_net) vlan_id=vlan_id, physical_network=physical_net)
elif (net_type == utils.NsxV3NetworkTypes.VLAN and
transparent_vlan):
# Use default VLAN transport zone if physical network not given
if physical_net is None:
physical_net = az._default_vlan_tz_uuid
elif net_type == utils.NsxV3NetworkTypes.GENEVE: elif net_type == utils.NsxV3NetworkTypes.GENEVE:
if vlan_id: if vlan_id:
err_msg = (_("Segmentation ID cannot be specified with " err_msg = (_("Segmentation ID cannot be specified with "
@ -873,12 +885,6 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
err_msg = (_('%(tz)s transport zone is required for ' err_msg = (_('%(tz)s transport zone is required for '
'creating a %(net)s provider network') % 'creating a %(net)s provider network') %
{'tz': tz_type, 'net': net_type}) {'tz': tz_type, 'net': net_type})
elif (transparent_vlan and
tz_type == nsxlib_tz.TRANSPORT_TYPE_VLAN):
raise NotImplementedError(_(
"Transparent support only for internal overlay "
"networks"))
if not err_msg: if not err_msg:
switch_mode = nsxlib_tz.get_host_switch_mode(physical_net) switch_mode = nsxlib_tz.get_host_switch_mode(physical_net)
@ -1054,9 +1060,6 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
nsx_net_id = None nsx_net_id = None
if validators.is_attr_set(external) and external: if validators.is_attr_set(external) and external:
if vlt:
raise NotImplementedError(_(
"Transparent support only for internal overlay networks"))
self._assert_on_external_net_with_qos(net_data) self._assert_on_external_net_with_qos(net_data)
is_provider_net, net_type, physical_net, vlan_id = ( is_provider_net, net_type, physical_net, vlan_id = (
self._validate_external_net_create(net_data)) self._validate_external_net_create(net_data))

View File

@ -533,7 +533,6 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
def test_create_provider_vlan_network_with_transparent(self): def test_create_provider_vlan_network_with_transparent(self):
providernet_args = {pnet.NETWORK_TYPE: 'vlan', providernet_args = {pnet.NETWORK_TYPE: 'vlan',
pnet.SEGMENTATION_ID: 11,
vlan_apidef.VLANTRANSPARENT: True} vlan_apidef.VLANTRANSPARENT: True}
with mock.patch('vmware_nsxlib.v3.core_resources.NsxLibTransportZone.' with mock.patch('vmware_nsxlib.v3.core_resources.NsxLibTransportZone.'
'get_transport_type', return_value='VLAN'): 'get_transport_type', return_value='VLAN'):
@ -545,8 +544,7 @@ class TestNetworksV2(test_plugin.TestNetworksV2, NsxV3PluginTestCaseMixin):
pnet.SEGMENTATION_ID, pnet.SEGMENTATION_ID,
vlan_apidef.VLANTRANSPARENT)) vlan_apidef.VLANTRANSPARENT))
data = self.deserialize('json', result) data = self.deserialize('json', result)
# should fail self.assertEqual('vlan', data['network'].get(pnet.NETWORK_TYPE))
self.assertIn('NotImplementedError', data)
class TestSubnetsV2(test_plugin.TestSubnetsV2, NsxV3PluginTestCaseMixin): class TestSubnetsV2(test_plugin.TestSubnetsV2, NsxV3PluginTestCaseMixin):