[DHCP] Fix cleanup_deleted_ports method

Assume that only one port is deleted within 24 hours, in method
cleanup_deleted_ports the port removes from deleted_ports but not
removes from deleted_ports_ts
In this fix ports older than 1 day will be dropped from
deleted_ports and deleted_ports_ts properly

Closes-Bug: #1930838
Change-Id: I1af32e72abb9f101f9729aa6d1354c33a95c98ee
This commit is contained in:
Nurmatov Mamatisa 2021-06-04 12:04:27 +03:00
parent 0bdf3b56e0
commit 383f209b50
2 changed files with 9 additions and 2 deletions

View File

@ -1050,11 +1050,12 @@ class NetworkCache(object):
"self._deleted_ports" and "self._deleted_ports_ts".
"""
timestamp_min = timeutils.utcnow_ts() - DELETED_PORT_MAX_AGE
idx = None
for idx, (ts, port_id) in enumerate(self._deleted_ports_ts):
idx = 0
for (ts, port_id) in self._deleted_ports_ts:
if ts > timestamp_min:
break
self._deleted_ports.remove(port_id)
idx += 1
if idx:
self._deleted_ports_ts = self._deleted_ports_ts[idx:]

View File

@ -1719,6 +1719,12 @@ class TestNetworkCache(base.BaseTestCase):
nc = dhcp_agent.NetworkCache()
nc.add_to_deleted_ports(fake_port1.id)
utils.wait_until_true(lambda: nc._deleted_ports == set(), timeout=7)
self.assertEqual([], self.nc._deleted_ports_ts)
# check the second iteration is ok too
nc.add_to_deleted_ports(fake_port2.id)
utils.wait_until_true(lambda: nc._deleted_ports == set(), timeout=7)
self.assertEqual([], self.nc._deleted_ports_ts)
class FakePort1(object):