self.setup_agent_status_check(self.remove_networks_from_down_agents)
- def _agent_starting_up(self, context, agent):
+ def is_eligible_agent(self, context, active, agent):
+ # eligible agent is active or starting up
+ return (AgentSchedulerDbMixin.is_eligible_agent(active, agent) or
+ self.agent_starting_up(context, agent))
+
+ def agent_starting_up(self, context, agent):
"""Check if agent was just started.
Method returns True if agent is in its 'starting up' period.
for binding in bindings:
agent_id = binding.dhcp_agent['id']
if agent_id not in checked_agents:
- if self._agent_starting_up(context, binding.dhcp_agent):
+ if self.agent_starting_up(context, binding.dhcp_agent):
# When agent starts and it has many networks to process
# it may fail to send state reports in defined interval.
# The server will consider it dead and try to remove
return [binding.dhcp_agent
for binding in query
- if AgentSchedulerDbMixin.is_eligible_agent(active,
- binding.dhcp_agent)]
+ if self.is_eligible_agent(context, active,
+ binding.dhcp_agent)]
def add_network_to_dhcp_agent(self, context, id, network_id):
self._get_network(context, network_id)
from neutron.common import constants
from neutron import context
from neutron.db import agents_db
+from neutron.db import agentschedulers_db
from neutron.db import l3_agentschedulers_db
from neutron.extensions import agent
from neutron.extensions import dhcpagentscheduler
self._delete('ports', port2['port']['id'])
self.assertEqual(0, len(dhcp_agents['agents']))
+ def test_is_eligible_agent(self):
+ agent_startup = ('neutron.db.agentschedulers_db.'
+ 'DhcpAgentSchedulerDbMixin.agent_starting_up')
+ is_eligible_agent = ('neutron.db.agentschedulers_db.'
+ 'AgentSchedulerDbMixin.is_eligible_agent')
+ dhcp_mixin = agentschedulers_db.DhcpAgentSchedulerDbMixin()
+ with contextlib.nested(
+ mock.patch(agent_startup),
+ mock.patch(is_eligible_agent)
+ ) as (startup, elig):
+ tests = [(True, True),
+ (True, False),
+ (False, True),
+ (False, False)]
+ for rv1, rv2 in tests:
+ startup.return_value = rv1
+ elig.return_value = rv2
+ self.assertEqual(rv1 or rv2,
+ dhcp_mixin.is_eligible_agent(None,
+ None, None))
+
def test_network_scheduler_with_down_agent(self):
dhcp_hosta = {
'binary': 'neutron-dhcp-agent',
},
'agent_type': constants.AGENT_TYPE_DHCP}
self._register_one_agent_state(dhcp_hosta)
- is_agent_down_str = 'neutron.db.agents_db.AgentDbMixin.is_agent_down'
- with mock.patch(is_agent_down_str) as mock_is_agent_down:
- mock_is_agent_down.return_value = False
+ eligible_agent_str = ('neutron.db.agentschedulers_db.'
+ 'DhcpAgentSchedulerDbMixin.is_eligible_agent')
+ with mock.patch(eligible_agent_str) as eligible_agent:
+ eligible_agent.return_value = True
with self.port() as port:
dhcp_agents = self._list_dhcp_agents_hosting_network(
port['port']['network_id'])
self._delete('ports', port['port']['id'])
self._delete('networks', port['port']['network_id'])
self.assertEqual(1, len(dhcp_agents['agents']))
- with mock.patch(is_agent_down_str) as mock_is_agent_down:
- mock_is_agent_down.return_value = True
+
+ with mock.patch(eligible_agent_str) as eligible_agent:
+ eligible_agent.return_value = False
with self.port() as port:
dhcp_agents = self._list_dhcp_agents_hosting_network(
port['port']['network_id'])
dhcp_agent={'id': 'id2'}),
sched_db.NetworkDhcpAgentBinding(network_id='foo4',
dhcp_agent={'id': 'id2'})]
- with mock.patch.object(self, '_agent_starting_up',
+ with mock.patch.object(self, 'agent_starting_up',
side_effect=[True, False]):
res = [b for b in self._filter_bindings(None, bindings)]
# once per each agent id1 and id2