diff --git a/vmware_nsx/common/nsx_utils.py b/vmware_nsx/common/nsx_utils.py index b302ae4271..c2df718097 100644 --- a/vmware_nsx/common/nsx_utils.py +++ b/vmware_nsx/common/nsx_utils.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -from neutron.extensions import multiprovidernet as mpnet +from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef from neutron_lib.api.definitions import provider_net as pnet from neutron_lib.api import validators from neutron_lib import constants @@ -309,7 +309,7 @@ def convert_to_nsx_transport_zones( # Convert fields from provider request to nsx format if (network and not validators.is_attr_set( - network.get(mpnet.SEGMENTS))): + network.get(mpnet_apidef.SEGMENTS))): return [{"zone_uuid": default_tz_uuid, "transport_type": default_transport_type}] @@ -320,4 +320,4 @@ def convert_to_nsx_transport_zones( # If we end up here we need to convert multiprovider segments into nsx # transport zone configurations return _convert_segments_to_nsx_transport_zones( - network.get(mpnet.SEGMENTS), default_tz_uuid) + network.get(mpnet_apidef.SEGMENTS), default_tz_uuid) diff --git a/vmware_nsx/plugins/dvs/plugin.py b/vmware_nsx/plugins/dvs/plugin.py index e67eb009d1..348721b242 100644 --- a/vmware_nsx/plugins/dvs/plugin.py +++ b/vmware_nsx/plugins/dvs/plugin.py @@ -38,12 +38,12 @@ from neutron.db import portbindings_db from neutron.db import portsecurity_db from neutron.db import securitygroups_db from neutron.db import vlantransparent_db as vlan_ext_db -from neutron.extensions import multiprovidernet as mpnet from neutron.extensions import providernet from neutron.extensions import securitygroup as ext_sg from neutron.extensions import vlantransparent as vlan_ext from neutron.plugins.common import utils from neutron.quota import resource_registry +from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef from neutron_lib.api.definitions import portbindings as pbin from neutron_lib.api.definitions import provider_net as pnet from neutron_lib.api import validators @@ -163,7 +163,7 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin, network[pnet.SEGMENTATION_ID] = bindings[0].vlan_id else: # network come in though multiprovider networks api - network[mpnet.SEGMENTS] = [ + network[mpnet_apidef.SEGMENTS] = [ {pnet.NETWORK_TYPE: binding.binding_type, pnet.PHYSICAL_NETWORK: binding.phy_uuid, pnet.SEGMENTATION_ID: binding.vlan_id} diff --git a/vmware_nsx/plugins/nsx_mh/plugin.py b/vmware_nsx/plugins/nsx_mh/plugin.py index 8708618e6b..2f43e28357 100644 --- a/vmware_nsx/plugins/nsx_mh/plugin.py +++ b/vmware_nsx/plugins/nsx_mh/plugin.py @@ -60,16 +60,17 @@ from neutron.db import portbindings_db from neutron.db import portsecurity_db from neutron.db import quota_db # noqa from neutron.db import securitygroups_db -from neutron.extensions import multiprovidernet as mpnet from neutron.extensions import providernet from neutron.extensions import securitygroup as ext_sg from neutron.plugins.common import utils from neutron.quota import resource_registry from neutron_lib.api.definitions import extra_dhcp_opt as edo_ext from neutron_lib.api.definitions import extraroute as xroute_apidef +from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef from neutron_lib.api.definitions import portbindings as pbin from neutron_lib.api.definitions import provider_net as pnet from neutron_lib.exceptions import extraroute as xroute_exc +from neutron_lib.exceptions import multiprovidernet as mpnet_exc import vmware_nsx from vmware_nsx._i18n import _ @@ -778,11 +779,11 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin, webob.exc.HTTPBadRequest}) def _validate_provider_create(self, context, network): - segments = network.get(mpnet.SEGMENTS) + segments = network.get(mpnet_apidef.SEGMENTS) if not validators.is_attr_set(segments): return - mpnet.check_duplicate_segments(segments) + mpnet_apidef.check_duplicate_segments(segments) for segment in segments: network_type = segment.get(pnet.NETWORK_TYPE) physical_network = segment.get(pnet.PHYSICAL_NETWORK) @@ -867,7 +868,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin, network[pnet.SEGMENTATION_ID] = bindings[0].vlan_id else: # network come in though multiprovider networks api - network[mpnet.SEGMENTS] = [ + network[mpnet_apidef.SEGMENTS] = [ {pnet.NETWORK_TYPE: binding.binding_type, pnet.PHYSICAL_NETWORK: binding.phy_uuid, pnet.SEGMENTATION_ID: binding.vlan_id} @@ -919,10 +920,10 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin, if any(validators.is_attr_set(network.get(f)) for f in (pnet.NETWORK_TYPE, pnet.PHYSICAL_NETWORK, pnet.SEGMENTATION_ID)): - if validators.is_attr_set(network.get(mpnet.SEGMENTS)): - raise mpnet.SegmentsSetInConjunctionWithProviders() + if validators.is_attr_set(network.get(mpnet_apidef.SEGMENTS)): + raise mpnet_exc.SegmentsSetInConjunctionWithProviders() # convert to transport zone list - network[mpnet.SEGMENTS] = [ + network[mpnet_apidef.SEGMENTS] = [ {pnet.NETWORK_TYPE: network[pnet.NETWORK_TYPE], pnet.PHYSICAL_NETWORK: network[pnet.PHYSICAL_NETWORK], pnet.SEGMENTATION_ID: network[pnet.SEGMENTATION_ID]}] @@ -930,7 +931,7 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin, del network[pnet.PHYSICAL_NETWORK] del network[pnet.SEGMENTATION_ID] return False - if validators.is_attr_set(mpnet.SEGMENTS): + if validators.is_attr_set(mpnet_apidef.SEGMENTS): return True def create_network(self, context, network): @@ -985,10 +986,10 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin, nsx_db.add_neutron_nsx_network_mapping( context.session, new_net['id'], lswitch['uuid']) - if (net_data.get(mpnet.SEGMENTS) and + if (net_data.get(mpnet_apidef.SEGMENTS) and isinstance(provider_type, bool)): net_bindings = [] - for tz in net_data[mpnet.SEGMENTS]: + for tz in net_data[mpnet_apidef.SEGMENTS]: segmentation_id = tz.get(pnet.SEGMENTATION_ID, 0) segmentation_id_set = validators.is_attr_set( segmentation_id) diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py index 6974cfed9b..5d77898694 100644 --- a/vmware_nsx/plugins/nsx_v/plugin.py +++ b/vmware_nsx/plugins/nsx_v/plugin.py @@ -23,6 +23,7 @@ from neutron_lib.api.definitions import availability_zone as az_def from neutron_lib.api.definitions import external_net as extnet_apidef from neutron_lib.api.definitions import extra_dhcp_opt as ext_edo from neutron_lib.api.definitions import l3 as l3_apidef +from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef from neutron_lib.api.definitions import port as port_def from neutron_lib.api.definitions import port_security as psec from neutron_lib.api.definitions import provider_net as pnet @@ -39,6 +40,7 @@ from neutron_lib import exceptions as n_exc from neutron_lib.exceptions import allowedaddresspairs as addr_exc from neutron_lib.exceptions import flavors as flav_exc from neutron_lib.exceptions import l3 as l3_exc +from neutron_lib.exceptions import multiprovidernet as mpnet_exc from neutron_lib.exceptions import port_security as psec_exc from neutron_lib.plugins import constants as plugin_const from neutron_lib.plugins import directory @@ -78,7 +80,6 @@ from neutron.db import portsecurity_db from neutron.db import quota_db # noqa from neutron.db import securitygroups_db from neutron.db import vlantransparent_db -from neutron.extensions import multiprovidernet as mpnet from neutron.extensions import providernet from neutron.extensions import securitygroup as ext_sg from neutron.extensions import vlantransparent as ext_vlan @@ -639,11 +640,11 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, return az.vdn_scope_id def _validate_provider_create(self, context, network): - if not validators.is_attr_set(network.get(mpnet.SEGMENTS)): + if not validators.is_attr_set(network.get(mpnet_apidef.SEGMENTS)): return az_dvs = self._get_network_az_dvs_id(network) - for segment in network[mpnet.SEGMENTS]: + for segment in network[mpnet_apidef.SEGMENTS]: network_type = segment.get(pnet.NETWORK_TYPE) physical_network = segment.get(pnet.PHYSICAL_NETWORK) segmentation_id = segment.get(pnet.SEGMENTATION_ID) @@ -761,7 +762,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, network[pnet.SEGMENTATION_ID] = bindings[0].vlan_id else: # network come in though multiprovider networks api - network[mpnet.SEGMENTS] = [ + network[mpnet_apidef.SEGMENTS] = [ {pnet.NETWORK_TYPE: binding.binding_type, pnet.PHYSICAL_NETWORK: binding.phy_uuid, pnet.SEGMENTATION_ID: binding.vlan_id} @@ -850,10 +851,10 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, if any(validators.is_attr_set(network.get(f)) for f in (pnet.NETWORK_TYPE, pnet.PHYSICAL_NETWORK, pnet.SEGMENTATION_ID)): - if validators.is_attr_set(network.get(mpnet.SEGMENTS)): - raise mpnet.SegmentsSetInConjunctionWithProviders() + if validators.is_attr_set(network.get(mpnet_apidef.SEGMENTS)): + raise mpnet_exc.SegmentsSetInConjunctionWithProviders() # convert to transport zone list - network[mpnet.SEGMENTS] = [ + network[mpnet_apidef.SEGMENTS] = [ {pnet.NETWORK_TYPE: network[pnet.NETWORK_TYPE], pnet.PHYSICAL_NETWORK: network[pnet.PHYSICAL_NETWORK], pnet.SEGMENTATION_ID: network[pnet.SEGMENTATION_ID]}] @@ -861,7 +862,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, del network[pnet.PHYSICAL_NETWORK] del network[pnet.SEGMENTATION_ID] return False - if validators.is_attr_set(network.get(mpnet.SEGMENTS)): + if validators.is_attr_set(network.get(mpnet_apidef.SEGMENTS)): return True def _delete_backend_network(self, moref, dvs_id=None): @@ -908,7 +909,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, def _create_vlan_network_at_backend(self, net_data, dvs_id): network_name = self._get_vlan_network_name(net_data, dvs_id) - segment = net_data[mpnet.SEGMENTS][0] + segment = net_data[mpnet_apidef.SEGMENTS][0] vlan_tag = 0 if (segment.get(pnet.NETWORK_TYPE) == c_utils.NsxVNetworkTypes.VLAN): @@ -1099,7 +1100,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, free_ids = list(vlan_ids ^ used_ids_in_range) if len(free_ids) == 0: raise n_exc.NoNetworkAvailable() - net_data[mpnet.SEGMENTS][0][pnet.SEGMENTATION_ID] = free_ids[0] + net_data[mpnet_apidef.SEGMENTS][0][pnet.SEGMENTATION_ID] = free_ids[0] def create_network(self, context, network): net_data = network['network'] @@ -1118,7 +1119,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, generate_segmenation_id = False lock_vlan_creation = False if provider_type is not None: - segment = net_data[mpnet.SEGMENTS][0] + segment = net_data[mpnet_apidef.SEGMENTS][0] network_type = segment.get(pnet.NETWORK_TYPE) if network_type == c_utils.NsxVNetworkTypes.VLAN: physical_network = segment.get(pnet.PHYSICAL_NETWORK) @@ -1174,7 +1175,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, config_spec = {"virtualWireCreateSpec": virtual_wire} vdn_scope_id = self._get_network_vdn_scope_id(net_data) if provider_type is not None: - segment = net_data[mpnet.SEGMENTS][0] + segment = net_data[mpnet_apidef.SEGMENTS][0] if validators.is_attr_set( segment.get(pnet.PHYSICAL_NETWORK)): vdn_scope_id = segment.get(pnet.PHYSICAL_NETWORK) @@ -1191,11 +1192,11 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, if vlt: raise NotImplementedError(_("Transparent support only " "for VXLANs")) - segment = net_data[mpnet.SEGMENTS][0] + segment = net_data[mpnet_apidef.SEGMENTS][0] net_morefs = [segment.get(pnet.PHYSICAL_NETWORK)] dvs_net_ids = [net_data['name']] else: - segment = net_data[mpnet.SEGMENTS][0] + segment = net_data[mpnet_apidef.SEGMENTS][0] physical_network = segment.get(pnet.PHYSICAL_NETWORK) # Retrieve the list of dvs-ids from physical network. # If physical_network attr is not set, retrieve a list @@ -1276,10 +1277,10 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, # DB Operations for setting the network as external self._process_l3_create(context, new_net, net_data) - if (net_data.get(mpnet.SEGMENTS) and + if (net_data.get(mpnet_apidef.SEGMENTS) and isinstance(provider_type, bool)): net_bindings = [] - for tz in net_data[mpnet.SEGMENTS]: + for tz in net_data[mpnet_apidef.SEGMENTS]: network_type = tz.get(pnet.NETWORK_TYPE) segmentation_id = tz.get(pnet.SEGMENTATION_ID, 0) segmentation_id_set = validators.is_attr_set( diff --git a/vmware_nsx/services/ipam/nsx_v/driver.py b/vmware_nsx/services/ipam/nsx_v/driver.py index a5211ae410..d195db11bc 100644 --- a/vmware_nsx/services/ipam/nsx_v/driver.py +++ b/vmware_nsx/services/ipam/nsx_v/driver.py @@ -17,10 +17,10 @@ import xml.etree.ElementTree as et import netaddr -from neutron.extensions import multiprovidernet as mpnet from neutron.ipam import exceptions as ipam_exc from neutron.ipam import requests as ipam_req from neutron_lib.api.definitions import external_net as extnet_apidef +from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef from neutron_lib.api.definitions import provider_net as pnet from neutron_lib.api import validators from oslo_log import log as logging @@ -54,7 +54,7 @@ class NsxvIpamDriver(common.NsxAbstractIpamDriver, NsxVIpamBase): if network.get(extnet_apidef.EXTERNAL): # external network return True - if (validators.is_attr_set(network.get(mpnet.SEGMENTS)) or + if (validators.is_attr_set(network.get(mpnet_apidef.SEGMENTS)) or validators.is_attr_set(network.get(pnet.NETWORK_TYPE))): # provider network return True diff --git a/vmware_nsx/tests/unit/extensions/test_providernet.py b/vmware_nsx/tests/unit/extensions/test_providernet.py index 9a65f3dc26..edf641ff62 100644 --- a/vmware_nsx/tests/unit/extensions/test_providernet.py +++ b/vmware_nsx/tests/unit/extensions/test_providernet.py @@ -16,7 +16,7 @@ from oslo_config import cfg import webob.exc -from neutron.extensions import multiprovidernet as mpnet +from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef from neutron_lib.api.definitions import provider_net as pnet from vmware_nsx.tests import unit as vmware from vmware_nsx.tests.unit.nsx_mh import test_plugin as test_nsx_plugin @@ -79,7 +79,7 @@ class TestMultiProviderNetworks(test_nsx_plugin.NsxPluginV2TestCase): self.assertEqual(network['network'][pnet.NETWORK_TYPE], 'vlan') self.assertEqual(network['network'][pnet.PHYSICAL_NETWORK], 'physnet1') self.assertEqual(network['network'][pnet.SEGMENTATION_ID], 1) - self.assertNotIn(mpnet.SEGMENTS, network['network']) + self.assertNotIn(mpnet_apidef.SEGMENTS, network['network']) def test_create_network_provider_flat(self): data = {'network': {'name': 'net1', @@ -92,11 +92,11 @@ class TestMultiProviderNetworks(test_nsx_plugin.NsxPluginV2TestCase): self.assertEqual('flat', network['network'][pnet.NETWORK_TYPE]) self.assertEqual('physnet1', network['network'][pnet.PHYSICAL_NETWORK]) self.assertEqual(0, network['network'][pnet.SEGMENTATION_ID]) - self.assertNotIn(mpnet.SEGMENTS, network['network']) + self.assertNotIn(mpnet_apidef.SEGMENTS, network['network']) def test_create_network_single_multiple_provider(self): data = {'network': {'name': 'net1', - mpnet.SEGMENTS: + mpnet_apidef.SEGMENTS: [{pnet.NETWORK_TYPE: 'vlan', pnet.PHYSICAL_NETWORK: 'physnet1', pnet.SEGMENTATION_ID: 1}], @@ -106,7 +106,7 @@ class TestMultiProviderNetworks(test_nsx_plugin.NsxPluginV2TestCase): for provider_field in [pnet.NETWORK_TYPE, pnet.PHYSICAL_NETWORK, pnet.SEGMENTATION_ID]: self.assertNotIn(provider_field, network['network']) - tz = network['network'][mpnet.SEGMENTS][0] + tz = network['network'][mpnet_apidef.SEGMENTS][0] self.assertEqual(tz[pnet.NETWORK_TYPE], 'vlan') self.assertEqual(tz[pnet.PHYSICAL_NETWORK], 'physnet1') self.assertEqual(tz[pnet.SEGMENTATION_ID], 1) @@ -114,14 +114,14 @@ class TestMultiProviderNetworks(test_nsx_plugin.NsxPluginV2TestCase): # Tests get_network() net_req = self.new_show_request('networks', network['network']['id']) network = self.deserialize(self.fmt, net_req.get_response(self.api)) - tz = network['network'][mpnet.SEGMENTS][0] + tz = network['network'][mpnet_apidef.SEGMENTS][0] self.assertEqual(tz[pnet.NETWORK_TYPE], 'vlan') self.assertEqual(tz[pnet.PHYSICAL_NETWORK], 'physnet1') self.assertEqual(tz[pnet.SEGMENTATION_ID], 1) def test_create_network_multprovider(self): data = {'network': {'name': 'net1', - mpnet.SEGMENTS: + mpnet_apidef.SEGMENTS: [{pnet.NETWORK_TYPE: 'vlan', pnet.PHYSICAL_NETWORK: 'physnet1', pnet.SEGMENTATION_ID: 1}, @@ -131,8 +131,8 @@ class TestMultiProviderNetworks(test_nsx_plugin.NsxPluginV2TestCase): network_req = self.new_create_request('networks', data) network = self.deserialize(self.fmt, network_req.get_response(self.api)) - tz = network['network'][mpnet.SEGMENTS] - for tz in data['network'][mpnet.SEGMENTS]: + tz = network['network'][mpnet_apidef.SEGMENTS] + for tz in data['network'][mpnet_apidef.SEGMENTS]: for field in [pnet.NETWORK_TYPE, pnet.PHYSICAL_NETWORK, pnet.SEGMENTATION_ID]: self.assertEqual(tz.get(field), tz.get(field)) @@ -140,15 +140,15 @@ class TestMultiProviderNetworks(test_nsx_plugin.NsxPluginV2TestCase): # Tests get_network() net_req = self.new_show_request('networks', network['network']['id']) network = self.deserialize(self.fmt, net_req.get_response(self.api)) - tz = network['network'][mpnet.SEGMENTS] - for tz in data['network'][mpnet.SEGMENTS]: + tz = network['network'][mpnet_apidef.SEGMENTS] + for tz in data['network'][mpnet_apidef.SEGMENTS]: for field in [pnet.NETWORK_TYPE, pnet.PHYSICAL_NETWORK, pnet.SEGMENTATION_ID]: self.assertEqual(tz.get(field), tz.get(field)) def test_create_network_with_provider_and_multiprovider_fail(self): data = {'network': {'name': 'net1', - mpnet.SEGMENTS: + mpnet_apidef.SEGMENTS: [{pnet.NETWORK_TYPE: 'vlan', pnet.PHYSICAL_NETWORK: 'physnet1', pnet.SEGMENTATION_ID: 1}], @@ -163,7 +163,7 @@ class TestMultiProviderNetworks(test_nsx_plugin.NsxPluginV2TestCase): def test_create_network_duplicate_segments(self): data = {'network': {'name': 'net1', - mpnet.SEGMENTS: + mpnet_apidef.SEGMENTS: [{pnet.NETWORK_TYPE: 'vlan', pnet.PHYSICAL_NETWORK: 'physnet1', pnet.SEGMENTATION_ID: 1}, diff --git a/vmware_nsx/tests/unit/nsx_mh/test_utils.py b/vmware_nsx/tests/unit/nsx_mh/test_utils.py index 4647c9f59d..b9f9f14b8d 100644 --- a/vmware_nsx/tests/unit/nsx_mh/test_utils.py +++ b/vmware_nsx/tests/unit/nsx_mh/test_utils.py @@ -15,8 +15,8 @@ import mock from neutron.db import api as db_api -from neutron.extensions import multiprovidernet as mpnet from neutron.tests import base +from neutron_lib.api.definitions import multiprovidernet as mpnet_apidef from neutron_lib.api.definitions import provider_net as pnet from oslo_utils import uuidutils @@ -358,7 +358,8 @@ class NsxUtilsTestCase(base.BaseTestCase): pnet.PHYSICAL_NETWORK: 'whatever_tz_2'}, ] results = nsx_utils.convert_to_nsx_transport_zones( - 'meh_zone_uuid', {'id': 'whatever_net', mpnet.SEGMENTS: segments}) + 'meh_zone_uuid', + {'id': 'whatever_net', mpnet_apidef.SEGMENTS: segments}) self._verify_nsx_transport_zones(results)