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". "self._deleted_ports" and "self._deleted_ports_ts".
""" """
timestamp_min = timeutils.utcnow_ts() - DELETED_PORT_MAX_AGE timestamp_min = timeutils.utcnow_ts() - DELETED_PORT_MAX_AGE
idx = None idx = 0
for idx, (ts, port_id) in enumerate(self._deleted_ports_ts): for (ts, port_id) in self._deleted_ports_ts:
if ts > timestamp_min: if ts > timestamp_min:
break break
self._deleted_ports.remove(port_id) self._deleted_ports.remove(port_id)
idx += 1
if idx: if idx:
self._deleted_ports_ts = self._deleted_ports_ts[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 = dhcp_agent.NetworkCache()
nc.add_to_deleted_ports(fake_port1.id) nc.add_to_deleted_ports(fake_port1.id)
utils.wait_until_true(lambda: nc._deleted_ports == set(), timeout=7) 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): class FakePort1(object):