Raise InvalidInput exception on provider-net creation without seg_id

This patch raises InvalidInput to users when they create provider net
without seg_id if ml2_vlan_ranges just sets the physical net name. This
must be more friendly.

Closes-Bug: #1649750
Change-Id: I9831d1a5b5764dcb8ee94641a3afc3991e56f8c2
This commit is contained in:
ZhaoBo 2016-12-13 16:39:34 +08:00
parent 31e5176a36
commit 1376df7873
2 changed files with 13 additions and 0 deletions

View File

@ -150,6 +150,12 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
{'min': p_const.MIN_VLAN_TAG,
'max': p_const.MAX_VLAN_TAG})
raise exc.InvalidInput(error_message=msg)
else:
if not self.network_vlan_ranges.get(physical_network):
msg = (_("Physical network %s requires segmentation_id "
"to be specified when creating a provider "
"network") % physical_network)
raise exc.InvalidInput(error_message=msg)
elif segmentation_id:
msg = _("segmentation_id requires physical_network for VLAN "
"provider network")

View File

@ -122,6 +122,13 @@ class VlanTypeTest(testlib_api.SqlTestCase):
self.driver.validate_provider_segment,
segment)
def test_validate_provider_segment_with_physical_network_only(self):
segment = {api.NETWORK_TYPE: p_const.TYPE_VLAN,
api.PHYSICAL_NETWORK: PROVIDER_NET}
self.assertRaises(exc.InvalidInput,
self.driver.validate_provider_segment,
segment)
def test_sync_vlan_allocations(self):
def check_in_ranges(network_vlan_ranges):
vlan_min, vlan_max = network_vlan_ranges[TENANT_NET][0]