diff --git a/neutron/plugins/ml2/drivers/type_vlan.py b/neutron/plugins/ml2/drivers/type_vlan.py index fbc1f59e409..7e8731a4135 100644 --- a/neutron/plugins/ml2/drivers/type_vlan.py +++ b/neutron/plugins/ml2/drivers/type_vlan.py @@ -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) diff --git a/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py b/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py index 657edea9d85..92b8af58cd8 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py +++ b/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py @@ -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,