From 2a61574f812a7e12fa25ee6933c8ddc595849182 Mon Sep 17 00:00:00 2001 From: Matt Vinall Date: Thu, 9 Jul 2020 21:08:21 +0100 Subject: [PATCH] fix dhcp bulk reload exceptions 1886969 - The bulk reload code was written for python2 and caused an exception running under python3. This change works under python3. 1890027 - There was an additional exception triggered when deleting networks - reading the network from the cache returned 'None' and this was not properly checked before use. Change-Id: I4e546c0e37146b1f34d8b5e6637c407b0c04ad4d Closes-Bug: 1886969 Closes-Bug: 1890027 Signed-off-by: Matt Vinall (cherry picked from commit 20b138ff3118029e86f0525695160c4c7ca8b551) --- neutron/agent/dhcp/agent.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/neutron/agent/dhcp/agent.py b/neutron/agent/dhcp/agent.py index a3b21e041f6..8ddeca14096 100644 --- a/neutron/agent/dhcp/agent.py +++ b/neutron/agent/dhcp/agent.py @@ -165,10 +165,15 @@ class DhcpAgent(manager.Manager): def _reload_bulk_allocations(self): while True: - for network_id in self._network_bulk_allocations.keys(): + # No need to lock access to _network_bulk_allocations because + # greenthreads multi-task co-operatively. + to_reload = self._network_bulk_allocations.keys() + self._network_bulk_allocations = {} + + for network_id in to_reload: network = self.cache.get_network_by_id(network_id) - self.call_driver('bulk_reload_allocations', network) - del self._network_bulk_allocations[network_id] + if network is not None: + self.call_driver('bulk_reload_allocations', network) eventlet.greenthread.sleep(self.conf.bulk_reload_interval) def call_driver(self, action, network, **action_kwargs):