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
This commit is contained in:
parent
6db61d0704
commit
8df2f69b6f
|
@ -405,9 +405,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)
|
||||
|
||||
|
@ -426,7 +426,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
|
||||
|
|
|
@ -1466,6 +1466,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,
|
||||
|
|
Loading…
Reference in New Issue