]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Skip rescheduling networks if no DHCP agents available
authorEugene Nikanorov <enikanorov@mirantis.com>
Thu, 4 Jun 2015 21:46:22 +0000 (01:46 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Mon, 15 Jun 2015 01:42:59 +0000 (05:42 +0400)
This eliminates the problem of unscheduled networks in case
of communication failure between agents and servers which
can occur if messaging queue service fails.

Change-Id: Ied4fa301fc3d475bee25c47f3a01c2381ae9a01e
Closes-Bug: #1461714

neutron/db/agentschedulers_db.py
neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py

index 61eff9b07cbbe77ec25c9f2a1cc52070aa5f9ef5..b9d9c11dbe59d6c1a213be6ba2cf9a1d72cc5128 100644 (file)
@@ -271,7 +271,16 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
         dhcp_notifier = self.agent_notifiers.get(constants.AGENT_TYPE_DHCP)
 
         try:
-            for binding in self._filter_bindings(context, down_bindings):
+            dead_bindings = [b for b in
+                             self._filter_bindings(context, down_bindings)]
+            dead_agents = set([b.dhcp_agent_id for b in dead_bindings])
+            agents = self.get_agents_db(
+                context, {'agent_type': [constants.AGENT_TYPE_DHCP]})
+            if len(agents) == len(dead_agents):
+                LOG.warn(_LW("No DHCP agents available, "
+                             "skipping rescheduling"))
+                return
+            for binding in dead_bindings:
                 LOG.warn(_LW("Removing network %(network)s from agent "
                              "%(agent)s because the agent did not report "
                              "to the server in the last %(dead_time)s "
index 5ee1adb16cd4a2338544bd379f826a3d00133624..260a5b01a8d85f0f66abe63be749d75a905179e5 100644 (file)
@@ -21,6 +21,7 @@ import testscenarios
 from neutron.common import constants
 from neutron import context
 from neutron.db import agentschedulers_db as sched_db
+from neutron.db import common_db_mixin
 from neutron.db import models_v2
 from neutron.extensions import dhcpagentscheduler
 from neutron.scheduler import dhcp_agent_scheduler
@@ -177,7 +178,8 @@ class TestAutoScheduleNetworks(TestDhcpSchedulerBaseTestCase):
 
 
 class TestNetworksFailover(TestDhcpSchedulerBaseTestCase,
-                           sched_db.DhcpAgentSchedulerDbMixin):
+                           sched_db.DhcpAgentSchedulerDbMixin,
+                           common_db_mixin.CommonDbMixin):
     def test_reschedule_network_from_down_agent(self):
         agents = self._create_and_set_agents_down(['host-a', 'host-b'], 1)
         self._test_schedule_bind_network([agents[0]], self.network_id)
@@ -201,7 +203,7 @@ class TestNetworksFailover(TestDhcpSchedulerBaseTestCase,
                 mock.ANY, self.network_id, agents[1].host)
 
     def _test_failed_rescheduling(self, rn_side_effect=None):
-        agents = self._create_and_set_agents_down(['host-a'], 1)
+        agents = self._create_and_set_agents_down(['host-a', 'host-b'], 1)
         self._test_schedule_bind_network([agents[0]], self.network_id)
         with mock.patch.object(self,
                                'remove_network_from_dhcp_agent',
@@ -257,6 +259,14 @@ class TestNetworksFailover(TestDhcpSchedulerBaseTestCase,
             # just make sure that no exception is raised
             self.remove_networks_from_down_agents()
 
+    def test_reschedule_doesnt_occur_if_no_agents(self):
+        agents = self._create_and_set_agents_down(['host-a'], 1)
+        self._test_schedule_bind_network([agents[0]], self.network_id)
+        with mock.patch.object(
+            self, 'remove_network_from_dhcp_agent') as rn:
+            self.remove_networks_from_down_agents()
+            self.assertFalse(rn.called)
+
 
 class DHCPAgentWeightSchedulerTestCase(TestDhcpSchedulerBaseTestCase):
     """Unit test scenarios for WeightScheduler.schedule."""