NSX|V3+P: Add vlan-transparent flag to port vif details
Change-Id: I984f1e06b69f98c3e7aaca4db70a76725919e344
This commit is contained in:
parent
84a09a82fc
commit
95db356fc5
@ -1151,6 +1151,15 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
if bindings:
|
||||
return bindings[0].vlan_id
|
||||
|
||||
def _get_network_vlan_transparent(self, context, network_id):
|
||||
if not cfg.CONF.vlan_transparent:
|
||||
return False
|
||||
# Get this flag directly from DB to improve performance
|
||||
db_entry = context.session.query(models_v2.Network).filter_by(
|
||||
id=network_id).first()
|
||||
if db_entry:
|
||||
return True if db_entry.vlan_transparent else False
|
||||
|
||||
def _extend_nsx_port_dict_binding(self, context, port_data):
|
||||
# Not using the register api for this because we need the context
|
||||
# Some attributes were already initialized by _extend_port_portbinding
|
||||
@ -1173,6 +1182,8 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
||||
if port_data[pbin.VNIC_TYPE] != pbin.VNIC_NORMAL:
|
||||
port_data[pbin.VIF_DETAILS]['segmentation-id'] = (
|
||||
self._get_network_segmentation_id(context, net_id))
|
||||
port_data[pbin.VIF_DETAILS]['vlan-transparent'] = (
|
||||
self._get_network_vlan_transparent(context, net_id))
|
||||
|
||||
def _extend_qos_port_dict_binding(self, context, port):
|
||||
# add the qos policy id from the DB
|
||||
|
@ -998,6 +998,8 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
|
||||
def setUp(self):
|
||||
cfg.CONF.set_override('switching_profiles', [NSX_SWITCH_PROFILE],
|
||||
'nsx_v3')
|
||||
# add vlan transparent to the configuration
|
||||
cfg.CONF.set_override('vlan_transparent', True)
|
||||
super(TestPortsV2, self).setUp()
|
||||
self.plugin = directory.get_plugin()
|
||||
self.ctx = context.get_admin_context()
|
||||
@ -1844,6 +1846,8 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
|
||||
self.assertEqual(
|
||||
vlan_id,
|
||||
sport['port'][portbindings.VIF_DETAILS]['segmentation-id'])
|
||||
self.assertFalse(
|
||||
sport['port'][portbindings.VIF_DETAILS]['vlan-transparent'])
|
||||
|
||||
def test_create_port_vnic_direct_flat(self):
|
||||
self._test_create_port_vnic_direct(0)
|
||||
@ -1896,6 +1900,31 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
|
||||
**kwargs)
|
||||
self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
|
||||
|
||||
def test_create_transparent_vlan_port(self):
|
||||
providernet_args = {pnet.NETWORK_TYPE: 'vlan',
|
||||
vlan_apidef.VLANTRANSPARENT: True}
|
||||
with mock.patch('vmware_nsxlib.v3.core_resources.NsxLibTransportZone.'
|
||||
'get_transport_type', return_value='VLAN'):
|
||||
result = self._create_network(fmt='json', name='vlan_net',
|
||||
admin_state_up=True,
|
||||
providernet_args=providernet_args,
|
||||
arg_list=(
|
||||
pnet.NETWORK_TYPE,
|
||||
pnet.SEGMENTATION_ID,
|
||||
vlan_apidef.VLANTRANSPARENT))
|
||||
network = self.deserialize('json', result)
|
||||
net_id = network['network']['id']
|
||||
|
||||
with self.subnet(network=network):
|
||||
kwargs = {portbindings.VNIC_TYPE: portbindings.VNIC_DIRECT}
|
||||
net_id = network['network']['id']
|
||||
res = self._create_port(self.fmt, net_id=net_id,
|
||||
arg_list=(portbindings.VNIC_TYPE,),
|
||||
**kwargs)
|
||||
port = self.deserialize('json', res)
|
||||
self.assertTrue(
|
||||
port['port'][portbindings.VIF_DETAILS]['vlan-transparent'])
|
||||
|
||||
@common_v3.with_disable_dhcp
|
||||
def test_requested_subnet_id_v4_and_v6(self):
|
||||
return super(TestPortsV2, self).test_requested_subnet_id_v4_and_v6()
|
||||
|
Loading…
Reference in New Issue
Block a user