diff options
author | Aaron Rosen <aaronorosen@gmail.com> | 2014-09-08 16:07:15 -0700 |
---|---|---|
committer | Aaron Rosen <aaronorosen@gmail.com> | 2014-10-28 14:40:14 -0700 |
commit | e51d6474d44042459f485886ffcc14ed24b3967f (patch) | |
tree | 6e6b5a788458ca7651746db30d5e80e1bd8c4c65 | |
parent | 830142e6923ff5fa8303afc22b0b61c39a374fe8 (diff) | |
download | neutron-e51d6474d44042459f485886ffcc14ed24b3967f.tar.gz |
NSX: allow multiple networks with same vlan on different phy_net
Previously, the NSX plugin prevented one from creating multiple networks on
the same vlan even if they were being created on different physical_networks.
This patch corrects this issue and allows this to now occur.
Closes-bug: 1367034
Change-Id: I343449648304328dffdd5ba070491e05686ee22d
(cherry picked from commit 6d1f864531d169a54bc239561840176012629316)
-rw-r--r-- | neutron/plugins/vmware/dbexts/db.py | 5 | ||||
-rw-r--r-- | neutron/plugins/vmware/plugins/base.py | 12 | ||||
-rw-r--r-- | neutron/tests/unit/vmware/extensions/test_providernet.py | 9 |
3 files changed, 22 insertions, 4 deletions
diff --git a/neutron/plugins/vmware/dbexts/db.py b/neutron/plugins/vmware/dbexts/db.py index 6326460046..37dd6a77f7 100644 --- a/neutron/plugins/vmware/dbexts/db.py +++ b/neutron/plugins/vmware/dbexts/db.py @@ -33,10 +33,11 @@ def get_network_bindings(session, network_id): all()) -def get_network_bindings_by_vlanid(session, vlan_id): +def get_network_bindings_by_vlanid_and_physical_net(session, vlan_id, + phy_uuid): session = session or db.get_session() return (session.query(models.TzNetworkBinding). - filter_by(vlan_id=vlan_id). + filter_by(vlan_id=vlan_id, phy_uuid=phy_uuid). all()) diff --git a/neutron/plugins/vmware/plugins/base.py b/neutron/plugins/vmware/plugins/base.py index 3797891771..773e8b818e 100644 --- a/neutron/plugins/vmware/plugins/base.py +++ b/neutron/plugins/vmware/plugins/base.py @@ -756,10 +756,15 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin, for segment in segments: network_type = segment.get(pnet.NETWORK_TYPE) physical_network = segment.get(pnet.PHYSICAL_NETWORK) + physical_network_set = attr.is_attr_set(physical_network) segmentation_id = segment.get(pnet.SEGMENTATION_ID) network_type_set = attr.is_attr_set(network_type) segmentation_id_set = attr.is_attr_set(segmentation_id) + # If the physical_network_uuid isn't passed in use the default one. + if not physical_network_set: + physical_network = cfg.CONF.default_tz_uuid + err_msg = None if not network_type_set: err_msg = _("%s required") % pnet.NETWORK_TYPE @@ -782,8 +787,11 @@ class NsxPluginV2(addr_pair_db.AllowedAddressPairsMixin, 'max_id': constants.MAX_VLAN_TAG}) else: # Verify segment is not already allocated - bindings = nsx_db.get_network_bindings_by_vlanid( - context.session, segmentation_id) + bindings = ( + nsx_db.get_network_bindings_by_vlanid_and_physical_net( + context.session, segmentation_id, + physical_network) + ) if bindings: raise n_exc.VlanIdInUse( vlan_id=segmentation_id, diff --git a/neutron/tests/unit/vmware/extensions/test_providernet.py b/neutron/tests/unit/vmware/extensions/test_providernet.py index f6057f1451..6f27011b26 100644 --- a/neutron/tests/unit/vmware/extensions/test_providernet.py +++ b/neutron/tests/unit/vmware/extensions/test_providernet.py @@ -47,6 +47,15 @@ class TestProvidernet(test_nsx_plugin.NsxPluginV2TestCase): self.assertEqual(net['network'][pnet.SEGMENTATION_ID], 411) self.assertEqual(net['network'][pnet.PHYSICAL_NETWORK], 'physnet1') + # Test that we can create another provider network using the same + # vlan_id on another physical network. + data['network'][pnet.PHYSICAL_NETWORK] = 'physnet2' + network_req = self.new_create_request('networks', data, self.fmt) + net = self.deserialize(self.fmt, network_req.get_response(self.api)) + self.assertEqual(net['network'][pnet.NETWORK_TYPE], 'vlan') + self.assertEqual(net['network'][pnet.SEGMENTATION_ID], 411) + self.assertEqual(net['network'][pnet.PHYSICAL_NETWORK], 'physnet2') + class TestMultiProviderNetworks(test_nsx_plugin.NsxPluginV2TestCase): |