Browse Source

Merge "NSX|V3+P: Add vlan-transparent flag to port vif details"

changes/43/682243/1
Zuul 1 week ago
parent
commit
d47f459a6c
2 changed files with 40 additions and 0 deletions
  1. 11
    0
      vmware_nsx/plugins/common_v3/plugin.py
  2. 29
    0
      vmware_nsx/tests/unit/nsx_v3/test_plugin.py

+ 11
- 0
vmware_nsx/plugins/common_v3/plugin.py View File

@@ -1151,6 +1151,15 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
1151 1151
         if bindings:
1152 1152
             return bindings[0].vlan_id
1153 1153
 
1154
+    def _get_network_vlan_transparent(self, context, network_id):
1155
+        if not cfg.CONF.vlan_transparent:
1156
+            return False
1157
+        # Get this flag directly from DB to improve performance
1158
+        db_entry = context.session.query(models_v2.Network).filter_by(
1159
+            id=network_id).first()
1160
+        if db_entry:
1161
+            return True if db_entry.vlan_transparent else False
1162
+
1154 1163
     def _extend_nsx_port_dict_binding(self, context, port_data):
1155 1164
         # Not using the register api for this because we need the context
1156 1165
         # Some attributes were already initialized by _extend_port_portbinding
@@ -1173,6 +1182,8 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
1173 1182
             if port_data[pbin.VNIC_TYPE] != pbin.VNIC_NORMAL:
1174 1183
                 port_data[pbin.VIF_DETAILS]['segmentation-id'] = (
1175 1184
                     self._get_network_segmentation_id(context, net_id))
1185
+                port_data[pbin.VIF_DETAILS]['vlan-transparent'] = (
1186
+                    self._get_network_vlan_transparent(context, net_id))
1176 1187
 
1177 1188
     def _extend_qos_port_dict_binding(self, context, port):
1178 1189
         # add the qos policy id from the DB

+ 29
- 0
vmware_nsx/tests/unit/nsx_v3/test_plugin.py View File

@@ -998,6 +998,8 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
998 998
     def setUp(self):
999 999
         cfg.CONF.set_override('switching_profiles', [NSX_SWITCH_PROFILE],
1000 1000
                               'nsx_v3')
1001
+        # add vlan transparent to the configuration
1002
+        cfg.CONF.set_override('vlan_transparent', True)
1001 1003
         super(TestPortsV2, self).setUp()
1002 1004
         self.plugin = directory.get_plugin()
1003 1005
         self.ctx = context.get_admin_context()
@@ -1844,6 +1846,8 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
1844 1846
             self.assertEqual(
1845 1847
                 vlan_id,
1846 1848
                 sport['port'][portbindings.VIF_DETAILS]['segmentation-id'])
1849
+            self.assertFalse(
1850
+                sport['port'][portbindings.VIF_DETAILS]['vlan-transparent'])
1847 1851
 
1848 1852
     def test_create_port_vnic_direct_flat(self):
1849 1853
         self._test_create_port_vnic_direct(0)
@@ -1896,6 +1900,31 @@ class TestPortsV2(common_v3.NsxV3SubnetMixin,
1896 1900
                                     **kwargs)
1897 1901
             self.assertEqual(res.status_int, exc.HTTPBadRequest.code)
1898 1902
 
1903
+    def test_create_transparent_vlan_port(self):
1904
+        providernet_args = {pnet.NETWORK_TYPE: 'vlan',
1905
+                            vlan_apidef.VLANTRANSPARENT: True}
1906
+        with mock.patch('vmware_nsxlib.v3.core_resources.NsxLibTransportZone.'
1907
+                       'get_transport_type', return_value='VLAN'):
1908
+            result = self._create_network(fmt='json', name='vlan_net',
1909
+                                          admin_state_up=True,
1910
+                                          providernet_args=providernet_args,
1911
+                                          arg_list=(
1912
+                                              pnet.NETWORK_TYPE,
1913
+                                              pnet.SEGMENTATION_ID,
1914
+                                              vlan_apidef.VLANTRANSPARENT))
1915
+            network = self.deserialize('json', result)
1916
+            net_id = network['network']['id']
1917
+
1918
+            with self.subnet(network=network):
1919
+                kwargs = {portbindings.VNIC_TYPE: portbindings.VNIC_DIRECT}
1920
+                net_id = network['network']['id']
1921
+                res = self._create_port(self.fmt, net_id=net_id,
1922
+                                        arg_list=(portbindings.VNIC_TYPE,),
1923
+                                        **kwargs)
1924
+                port = self.deserialize('json', res)
1925
+                self.assertTrue(
1926
+                    port['port'][portbindings.VIF_DETAILS]['vlan-transparent'])
1927
+
1899 1928
     @common_v3.with_disable_dhcp
1900 1929
     def test_requested_subnet_id_v4_and_v6(self):
1901 1930
         return super(TestPortsV2, self).test_requested_subnet_id_v4_and_v6()

Loading…
Cancel
Save