Merge "Handle properly ObjectNotFound while deleting network from DHCP agent" into stable/xena

This commit is contained in:
Zuul 2022-05-06 10:10:12 +00:00 committed by Gerrit Code Review
commit c99f68dd27
2 changed files with 7 additions and 3 deletions

View File

@ -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

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,