]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Don't notify dead DHCP agent of removed networks
authorEugene Nikanorov <enikanorov@mirantis.com>
Mon, 9 Mar 2015 08:25:47 +0000 (11:25 +0300)
committerEugene Nikanorov <enikanorov@mirantis.com>
Tue, 10 Mar 2015 11:24:53 +0000 (14:24 +0300)
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

neutron/db/agentschedulers_db.py
neutron/tests/unit/test_dhcp_scheduler.py

index a9a879fe132ea4173ac02bd92c6a1ebe0d88674d..e330b0fc390322e74a7d9693f2c5144322087a5a 100644 (file)
@@ -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(
index 0daf26b66912eb6e0a44dd6f3e2361a5f2c19174..3865ee257b987b6215df464f3c29c75c7016ab8e 100644 (file)
@@ -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)