From ed7dd4dae0cf80f2314d9e113995e63a362b8295 Mon Sep 17 00:00:00 2001 From: Swaminathan Vasudevan Date: Wed, 4 Apr 2018 11:33:56 -0700 Subject: [PATCH] DVR: Check for item_allocator key before releasing item_allocator class maintains the allocation of items(link local address) from a given pool. There may be cases where the key has been already released or not being remembered while trying to release it. So it makes sense to lookup for the key before releasing the key. Change-Id: I34765dd3efa6c6742caeb7f6ae2ff14009dce6dd Closes-Bug: #1761260 --- neutron/agent/l3/item_allocator.py | 5 +++-- neutron/tests/unit/agent/l3/test_item_allocator.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/neutron/agent/l3/item_allocator.py b/neutron/agent/l3/item_allocator.py index 64543442f6c..ed14ede6c47 100644 --- a/neutron/agent/l3/item_allocator.py +++ b/neutron/agent/l3/item_allocator.py @@ -113,8 +113,9 @@ class ItemAllocator(object): return self.allocations[key] def release(self, key): - self.pool.add(self.allocations.pop(key)) - self._write_allocations() + if self.lookup(key): + self.pool.add(self.allocations.pop(key)) + self._write_allocations() def _write_allocations(self): current = ["%s,%s\n" % (k, v) for k, v in self.allocations.items()] diff --git a/neutron/tests/unit/agent/l3/test_item_allocator.py b/neutron/tests/unit/agent/l3/test_item_allocator.py index a614459ebac..407b079cd00 100644 --- a/neutron/tests/unit/agent/l3/test_item_allocator.py +++ b/neutron/tests/unit/agent/l3/test_item_allocator.py @@ -131,6 +131,9 @@ class TestItemAllocator(base.BaseTestCase): allocation = a.allocate('deadbeef') write.reset_mock() a.release('deadbeef') + # Just try to release the item again to see if it + # throws any error + a.release('deadbeef') self.assertNotIn('deadbeef', a.allocations) self.assertIn(allocation, a.pool)