Browse Source

Fix creation of vlan network with segmentation_id set to 0

In case when vlan network was created with segmentation_id=0 and without
physical_network given, it was passing validation of provider segment
and first available segmentation_id was choosen for network.
Problem was that in such case all available segmentation ids where
allocated and no other vlan network could be created later.

This patch fixes validation of segmentation_id when it is set to value 0.

Change-Id: Ic768deb84d544db832367f9a4b84a92729eee620
Closes-bug: #1840895
tags/15.0.0.0b1
Slawek Kaplonski 3 months ago
parent
commit
f01f3ae5dd
2 changed files with 18 additions and 7 deletions
  1. +2
    -2
      neutron/plugins/ml2/drivers/type_vlan.py
  2. +16
    -5
      neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py

+ 2
- 2
neutron/plugins/ml2/drivers/type_vlan.py View File

@@ -241,7 +241,7 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
msg = (_("physical_network '%s' unknown "
"for VLAN provider network") % physical_network)
raise exc.InvalidInput(error_message=msg)
if segmentation_id:
if segmentation_id is not None:
if not plugin_utils.is_valid_vlan_tag(segmentation_id):
msg = (_("segmentation_id out of range (%(min)s through "
"%(max)s)") %
@@ -254,7 +254,7 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
"to be specified when creating a provider "
"network") % physical_network)
raise exc.InvalidInput(error_message=msg)
elif segmentation_id:
elif segmentation_id is not None:
msg = _("segmentation_id requires physical_network for VLAN "
"provider network")
raise exc.InvalidInput(error_message=msg)

+ 16
- 5
neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py View File

@@ -100,6 +100,13 @@ class VlanTypeTest(testlib_api.SqlTestCase):
segment = {api.NETWORK_TYPE: p_const.TYPE_VLAN}
self.driver.validate_provider_segment(segment)

def test_validate_provider_segment_no_phys_network_seg_id_0(self):
segment = {api.NETWORK_TYPE: p_const.TYPE_VLAN,
api.SEGMENTATION_ID: 0}
self.assertRaises(exc.InvalidInput,
self.driver.validate_provider_segment,
segment)

def test_validate_provider_segment_with_missing_physical_network(self):
segment = {api.NETWORK_TYPE: p_const.TYPE_VLAN,
api.SEGMENTATION_ID: 1}
@@ -117,11 +124,15 @@ class VlanTypeTest(testlib_api.SqlTestCase):

def test_validate_provider_segment_with_invalid_segmentation_id(self):
segment = {api.NETWORK_TYPE: p_const.TYPE_VLAN,
api.PHYSICAL_NETWORK: PROVIDER_NET,
api.SEGMENTATION_ID: 5000}
self.assertRaises(exc.InvalidInput,
self.driver.validate_provider_segment,
segment)
api.PHYSICAL_NETWORK: PROVIDER_NET}
segmentation_ids = [
p_const.MIN_VLAN_TAG - 1,
p_const.MAX_VLAN_TAG + 1]
for segmentation_id in segmentation_ids:
segment[api.SEGMENTATION_ID] = segmentation_id
self.assertRaises(exc.InvalidInput,
self.driver.validate_provider_segment,
segment)

def test_validate_provider_segment_with_invalid_input(self):
segment = {api.NETWORK_TYPE: p_const.TYPE_VLAN,

Loading…
Cancel
Save