]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix: Skip rescheduling networks if no DHCP agents available
authorOleg Bondarev <obondarev@mirantis.com>
Wed, 5 Aug 2015 14:43:02 +0000 (17:43 +0300)
committerOleg Bondarev <obondarev@mirantis.com>
Wed, 5 Aug 2015 14:52:29 +0000 (17:52 +0300)
This fixes commit 1318437a0caf38e695a819848832a955fef7d909
which has inaccurate check for dead agents: in a case where
there is only one network scheduled to a subset of dhcp agents,
number of all dhcp agents will be not equal to the number of
dead binded agents

The unit test is updated to cover the described case.

Closes-Bug: #1461714
Change-Id: I1c9501316c931293aa8ba755a98779a7da27578d

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

index 212c6eb55a723113ed37701cb472d946bbae2dd9..153a420b9c0493e5d63f484cc3de02914c97fd07 100644 (file)
@@ -273,10 +273,11 @@ class DhcpAgentSchedulerDbMixin(dhcpagentscheduler
         try:
             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):
+            active_agents = [agent for agent in agents if
+                             self.is_eligible_agent(context, True, agent)]
+            if not active_agents:
                 LOG.warn(_LW("No DHCP agents available, "
                              "skipping rescheduling"))
                 return
index 75493454b239c779de3253cc1bd731391b692a8f..f7f5e92c4463d5a2c90639f9e272c25bf6a59971 100644 (file)
@@ -260,7 +260,7 @@ class TestNetworksFailover(TestDhcpSchedulerBaseTestCase,
             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)
+        agents = self._create_and_set_agents_down(['host-a', 'host-b'], 2)
         self._test_schedule_bind_network([agents[0]], self.network_id)
         with mock.patch.object(
             self, 'remove_network_from_dhcp_agent') as rn: