DVS: Prevent from creating a vlan network with same tag and dvs
Prevent from creating a vlan network with the same vlan tag and DVS id, displaying an error message to the user. Change-Id: I4f19812715f0b59ed528abd0bd2920a3e36c0505 Signed-off-by: Michal Kelner Mishali <mkelnermishal@vmware.com>
This commit is contained in:
parent
fe4a08d7b7
commit
85c9ae8071
@ -272,6 +272,14 @@ class NsxDvsV2(addr_pair_db.AllowedAddressPairsMixin,
|
||||
network_type_set = validators.is_attr_set(network_type)
|
||||
segmentation_id = net_data.get(pnet.SEGMENTATION_ID)
|
||||
segmentation_id_set = validators.is_attr_set(segmentation_id)
|
||||
physical_network = net_data.get(pnet.PHYSICAL_NETWORK)
|
||||
if network_type == 'vlan':
|
||||
bindings = nsx_db.get_network_bindings_by_vlanid_and_physical_net(
|
||||
context.session, segmentation_id, physical_network)
|
||||
if bindings:
|
||||
err_msg = _("Network with that dvs-id and vlan tag already "
|
||||
"exists")
|
||||
raise n_exc.InvalidInput(error_message=err_msg)
|
||||
if not context.is_admin:
|
||||
err_msg = _("Only an admin can create a DVS provider "
|
||||
"network")
|
||||
|
@ -381,3 +381,25 @@ class NeutronSimpleDvsTest(NeutronSimpleDvsTestCase):
|
||||
'admin_state_up': True}}
|
||||
self.assertRaises(exp.BadRequest, self._plugin.create_network,
|
||||
context.get_admin_context(), data)
|
||||
|
||||
def test_create_vlan_network_fail_duplicate_dvs(self):
|
||||
params = {'provider:network_type': 'vlan',
|
||||
'admin_state_up': True,
|
||||
'name': 'test_net',
|
||||
'tenant_id': 'fake_tenant',
|
||||
'shared': False,
|
||||
'provider:physical_network': 'fake-moid',
|
||||
'provider:segmentation_id': 7,
|
||||
'port_security_enabled': False}
|
||||
|
||||
with mock.patch.object(self._plugin._dvs,
|
||||
'add_port_group'),\
|
||||
mock.patch.object(dvs.DvsManager,
|
||||
'add_port_group'),\
|
||||
mock.patch.object(dvs.DvsManager,
|
||||
'get_dvs_moref_by_name',
|
||||
return_value=mock.MagicMock()):
|
||||
ctx = context.get_admin_context()
|
||||
self._plugin.create_network(ctx, {'network': params})
|
||||
self.assertRaises(exp.InvalidInput, self._plugin.create_network,
|
||||
ctx, {'network': params})
|
||||
|
Loading…
x
Reference in New Issue
Block a user