Merge "[DHCP] Fix cleanup_deleted_ports method"

This commit is contained in:
Zuul 2021-06-10 18:13:02 +00:00 committed by Gerrit Code Review
commit a61dc4613d
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):