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 "
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
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)
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',
# 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."""