From: Eugene Nikanorov Date: Mon, 9 Mar 2015 08:25:47 +0000 (+0300) Subject: Don't notify dead DHCP agent of removed networks X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=fa519080a17529db3bcd4c9000a649b26a225d11;p=openstack-build%2Fneutron-build.git Don't notify dead DHCP agent of removed networks This is needed to avoid a case when agent sees network removal notifications on startup. Processing of those notifications may overlap with processing of active networks and DHCP might be disabled on some of active networks as a result. Change-Id: I8271e8fce8b4d80a339f598b98467694774a299e Closes-Bug: #1429737 --- diff --git a/neutron/db/agentschedulers_db.py b/neutron/db/agentschedulers_db.py index a9a879fe1..e330b0fc3 100644 --- a/neutron/db/agentschedulers_db.py +++ b/neutron/db/agentschedulers_db.py @@ -264,9 +264,13 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler saved_binding = {'net': binding.network_id, 'agent': binding.dhcp_agent_id} try: + # do not notify agent if it considered dead + # so when it is restarted it won't see network delete + # notifications on its queue self.remove_network_from_dhcp_agent(context, binding.dhcp_agent_id, - binding.network_id) + binding.network_id, + notify=False) except dhcpagentscheduler.NetworkNotHostedByDhcpAgent: # measures against concurrent operation LOG.debug("Network %(net)s already removed from DHCP agent " @@ -325,7 +329,8 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler dhcp_notifier.network_added_to_agent( context, network_id, agent_db.host) - def remove_network_from_dhcp_agent(self, context, id, network_id): + def remove_network_from_dhcp_agent(self, context, id, network_id, + notify=True): agent = self._get_agent(context, id) with context.session.begin(subtransactions=True): try: @@ -349,6 +354,8 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler self.update_port(context, port['id'], dict(port=port)) query.delete() + if not notify: + return dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP) if dhcp_notifier: dhcp_notifier.network_removed_from_agent( diff --git a/neutron/tests/unit/test_dhcp_scheduler.py b/neutron/tests/unit/test_dhcp_scheduler.py index 0daf26b66..3865ee257 100644 --- a/neutron/tests/unit/test_dhcp_scheduler.py +++ b/neutron/tests/unit/test_dhcp_scheduler.py @@ -212,7 +212,8 @@ class TestNetworksFailover(TestDhcpSchedulerBaseTestCase, notifier = mock.MagicMock() self.agent_notifiers[constants.AGENT_TYPE_DHCP] = notifier self.remove_networks_from_down_agents() - rn.assert_called_with(mock.ANY, agents[0].id, self.network_id) + rn.assert_called_with(mock.ANY, agents[0].id, self.network_id, + notify=False) sch.assert_called_with(mock.ANY, {'id': self.network_id}) notifier.network_added_to_agent.assert_called_with( mock.ANY, self.network_id, agents[1].host) @@ -232,7 +233,8 @@ class TestNetworksFailover(TestDhcpSchedulerBaseTestCase, notifier = mock.MagicMock() self.agent_notifiers[constants.AGENT_TYPE_DHCP] = notifier self.remove_networks_from_down_agents() - rn.assert_called_with(mock.ANY, agents[0].id, self.network_id) + rn.assert_called_with(mock.ANY, agents[0].id, self.network_id, + notify=False) sch.assert_called_with(mock.ANY, {'id': self.network_id}) self.assertFalse(notifier.network_added_to_agent.called)