Browse Source

Merge "[DHCP] Fix cleanup_deleted_ports method"

changes/06/794606/2
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
a61dc4613d
2 changed files with 9 additions and 2 deletions
  1. +3
    -2
      neutron/agent/dhcp/agent.py
  2. +6
    -0
      neutron/tests/unit/agent/dhcp/test_agent.py

+ 3
- 2
neutron/agent/dhcp/agent.py 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:]


+ 6
- 0
neutron/tests/unit/agent/dhcp/test_agent.py 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):


Loading…
Cancel
Save