From 6c4bc1cf0585bdbe3701e0a2a87659881f5b1c73 Mon Sep 17 00:00:00 2001 From: zhsun Date: Mon, 15 Jan 2018 11:12:40 +0800 Subject: [PATCH] Fix delete vlan allocation error for ML2 Method "delete()" of ovo object should be invoked. Change-Id: I942e1a5072ce111beb94ffd6298bb3e23e2bb343 --- neutron/plugins/ml2/drivers/type_vlan.py | 2 +- .../unit/plugins/ml2/drivers/test_type_vlan.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/neutron/plugins/ml2/drivers/type_vlan.py b/neutron/plugins/ml2/drivers/type_vlan.py index 22177402524..56ea24fa5b1 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 550d9cd94de..4abcf3aa404 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,