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
(cherry picked from commit f01f3ae5dd)
This commit is contained in:
Slawek Kaplonski 2019-08-30 22:32:19 +02:00
parent 053e9b662c
commit f050abab45
2 changed files with 18 additions and 7 deletions

View File

@ -151,7 +151,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)") %
@ -164,7 +164,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)

View File

@ -97,6 +97,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}
@ -114,11 +121,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,