Browse Source

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

stable/stein
Zuul 1 week ago
parent
commit
273642cd9a
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

@@ -1137,6 +1137,15 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
1137 1137
         if bindings:
1138 1138
             return bindings[0].vlan_id
1139 1139
 
1140
+    def _get_network_vlan_transparent(self, context, network_id):
1141
+        if not cfg.CONF.vlan_transparent:
1142
+            return False
1143
+        # Get this flag directly from DB to improve performance
1144
+        db_entry = context.session.query(models_v2.Network).filter_by(
1145
+            id=network_id).first()
1146
+        if db_entry:
1147
+            return True if db_entry.vlan_transparent else False
1148
+
1140 1149
     def _extend_nsx_port_dict_binding(self, context, port_data):
1141 1150
         # Not using the register api for this because we need the context
1142 1151
         # Some attributes were already initialized by _extend_port_portbinding
@@ -1159,6 +1168,8 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
1159 1168
             if port_data[pbin.VNIC_TYPE] != pbin.VNIC_NORMAL:
1160 1169
                 port_data[pbin.VIF_DETAILS]['segmentation-id'] = (
1161 1170
                     self._get_network_segmentation_id(context, net_id))
1171
+                port_data[pbin.VIF_DETAILS]['vlan-transparent'] = (
1172
+                    self._get_network_vlan_transparent(context, net_id))
1162 1173
 
1163 1174
     def _extend_qos_port_dict_binding(self, context, port):
1164 1175
         # add the qos policy id from the DB

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

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

Loading…
Cancel
Save