Handle properly ObjectNotFound while deleting network from DHCP agent

In case when 2 neutron servers are trying to remove network from the
same DHCP agent it may happend that one of them will not be able
to find binding object anymore thus deletion of that binding object
will raise ObjectNotFound exception.
This patch adds proper handling of such case to not raise ugly
stacktrace in neutron logs.

Closes-Bug: #1970759
Change-Id: I67d516c4583aa0c20416114b92a6d69ece5b970c
(cherry picked from commit 8df2f69b6f)
This commit is contained in:
Slawek Kaplonski 2022-04-28 16:51:25 +02:00
parent 2028c152c6
commit 882b381ccc
2 changed files with 7 additions and 3 deletions

View File

@ -407,9 +407,9 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
def remove_network_from_dhcp_agent(self, context, id, network_id,
notify=True):
agent = self._get_agent(context, id)
binding_obj = network.NetworkDhcpAgentBinding.get_object(
deleted_bindings = network.NetworkDhcpAgentBinding.delete_objects(
context, network_id=network_id, dhcp_agent_id=id)
if not binding_obj:
if not deleted_bindings:
raise das_exc.NetworkNotHostedByDhcpAgent(
network_id=network_id, agent_id=id)
@ -428,7 +428,6 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
except n_exc.PortNotFound:
LOG.debug("DHCP port %s has been deleted concurrently",
port['id'])
binding_obj.delete()
if not notify:
return

View File

@ -1472,6 +1472,11 @@ class OvsDhcpAgentNotifierTestCase(test_agent.AgentDBTestMixIn,
self._remove_network_from_dhcp_agent(hosta_id,
network_id)
# Call it second time, it should be already deleted so should 409 be
# returned this time
self._remove_network_from_dhcp_agent(
hosta_id, network_id,
expected_code=exc.HTTPConflict.code)
self.dhcp_notifier_cast.assert_called_with(
mock.ANY, 'network_delete_end',
{'network_id': network_id,