diff options
author | Slawek Kaplonski <skaplons@redhat.com> | 2022-04-28 16:51:25 +0200 |
---|---|---|
committer | Slawek Kaplonski <skaplons@redhat.com> | 2022-05-05 10:47:16 +0000 |
commit | d739ceec23b3a17eae7160ce63193c66842d206e (patch) | |
tree | 7775876efe592017ece91f369cc2cca89deed378 | |
parent | 5eb6c6fef28fc9f4f6cb20098ff24a228298f805 (diff) | |
download | neutron-d739ceec23b3a17eae7160ce63193c66842d206e.tar.gz |
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 8df2f69b6f93fd964cc96efb42d085063b90a8e6)
-rw-r--r-- | neutron/db/agentschedulers_db.py | 5 | ||||
-rw-r--r-- | neutron/tests/unit/db/test_agentschedulers_db.py | 5 |
2 files changed, 7 insertions, 3 deletions
diff --git a/neutron/db/agentschedulers_db.py b/neutron/db/agentschedulers_db.py index 4400fc5751..c03b3289c8 100644 --- a/neutron/db/agentschedulers_db.py +++ b/neutron/db/agentschedulers_db.py @@ -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 diff --git a/neutron/tests/unit/db/test_agentschedulers_db.py b/neutron/tests/unit/db/test_agentschedulers_db.py index 91ffc15366..13a6a71d88 100644 --- a/neutron/tests/unit/db/test_agentschedulers_db.py +++ b/neutron/tests/unit/db/test_agentschedulers_db.py @@ -1443,6 +1443,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, |