From: Oleg Bondarev Date: Wed, 5 Aug 2015 14:43:02 +0000 (+0300) Subject: Fix: Skip rescheduling networks if no DHCP agents available X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6e3817433e443fd008ef433f54068c197c78465b;p=openstack-build%2Fneutron-build.git Fix: Skip rescheduling networks if no DHCP agents available 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 --- diff --git a/neutron/db/agentschedulers_db.py b/neutron/db/agentschedulers_db.py index 212c6eb55..153a420b9 100644 --- a/neutron/db/agentschedulers_db.py +++ b/neutron/db/agentschedulers_db.py @@ -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 diff --git a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py index 75493454b..f7f5e92c4 100644 --- a/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_dhcp_agent_scheduler.py @@ -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: