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
(cherry picked from commit ed7dd4dae0
)
This commit is contained in:
parent
a8fed790b7
commit
d4aa8f49f1
|
@ -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()]
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue