diff --git a/neutron/plugins/ml2/drivers/type_vlan.py b/neutron/plugins/ml2/drivers/type_vlan.py index 622854cb588..d76832b84c1 100644 --- a/neutron/plugins/ml2/drivers/type_vlan.py +++ b/neutron/plugins/ml2/drivers/type_vlan.py @@ -130,7 +130,7 @@ class VlanTypeDriver(helpers.SegmentTypeDriver): {'vlan_id': alloc.vlan_id, 'physical_network': alloc.physical_network}) - ctx.session.delete(alloc) + alloc.delete() def get_type(self): return p_const.TYPE_VLAN 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 6b39fc56c78..afc95b10d96 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py +++ b/neutron/tests/unit/plugins/ml2/drivers/test_type_vlan.py @@ -37,6 +37,9 @@ UPDATED_VLAN_RANGES = { PROVIDER_NET: [], TENANT_NET: [(VLAN_MIN + 5, VLAN_MAX + 5)], } +EMPTY_VLAN_RANGES = { + PROVIDER_NET: [] +} CORE_PLUGIN = 'ml2' @@ -158,6 +161,19 @@ class VlanTypeTest(testlib_api.SqlTestCase): self.driver._sync_vlan_allocations() check_in_ranges(UPDATED_VLAN_RANGES) + self.driver.network_vlan_ranges = EMPTY_VLAN_RANGES + self.driver._sync_vlan_allocations() + + vlan_min, vlan_max = UPDATED_VLAN_RANGES[TENANT_NET][0] + segment = {api.NETWORK_TYPE: p_const.TYPE_VLAN, + api.PHYSICAL_NETWORK: TENANT_NET} + segment[api.SEGMENTATION_ID] = vlan_min + self.assertIsNone( + self._get_allocation(self.context, segment)) + segment[api.SEGMENTATION_ID] = vlan_max + self.assertIsNone( + self._get_allocation(self.context, segment)) + def test_reserve_provider_segment(self): segment = {api.NETWORK_TYPE: p_const.TYPE_VLAN, api.PHYSICAL_NETWORK: PROVIDER_NET,