Skip to content

Commit db2c126

Browse files
committed
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 8df2f69)
1 parent 609508b commit db2c126

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

neutron/db/agentschedulers_db.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,9 @@ def add_network_to_dhcp_agent(self, context, id, network_id):
405405
def remove_network_from_dhcp_agent(self, context, id, network_id,
406406
notify=True):
407407
agent = self._get_agent(context, id)
408-
binding_obj = network.NetworkDhcpAgentBinding.get_object(
408+
deleted_bindings = network.NetworkDhcpAgentBinding.delete_objects(
409409
context, network_id=network_id, dhcp_agent_id=id)
410-
if not binding_obj:
410+
if not deleted_bindings:
411411
raise das_exc.NetworkNotHostedByDhcpAgent(
412412
network_id=network_id, agent_id=id)
413413

@@ -426,7 +426,6 @@ def remove_network_from_dhcp_agent(self, context, id, network_id,
426426
except n_exc.PortNotFound:
427427
LOG.debug("DHCP port %s has been deleted concurrently",
428428
port['id'])
429-
binding_obj.delete()
430429

431430
if not notify:
432431
return

neutron/tests/unit/db/test_agentschedulers_db.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,6 +1466,11 @@ def test_network_remove_from_dhcp_agent_notification(self):
14661466

14671467
self._remove_network_from_dhcp_agent(hosta_id,
14681468
network_id)
1469+
# Call it second time, it should be already deleted so should 409 be
1470+
# returned this time
1471+
self._remove_network_from_dhcp_agent(
1472+
hosta_id, network_id,
1473+
expected_code=exc.HTTPConflict.code)
14691474
self.dhcp_notifier_cast.assert_called_with(
14701475
mock.ANY, 'network_delete_end',
14711476
{'network_id': network_id,

0 commit comments

Comments
 (0)