avoid auto scheduling one dhcp agent twice.

Bug #1183173

Change-Id: Iff7b23faae50e6736b253ca5a2b1280451127200
This commit is contained in:
gongysh 2013-05-23 11:45:49 +08:00
parent 1e57943840
commit 7e3cef2d7b
2 changed files with 20 additions and 1 deletions

View File

@ -100,7 +100,6 @@ class ChanceScheduler(object):
dhcp_agent.heartbeat_timestamp): dhcp_agent.heartbeat_timestamp):
LOG.warn(_('DHCP agent %s is not active'), dhcp_agent.id) LOG.warn(_('DHCP agent %s is not active'), dhcp_agent.id)
continue continue
#TODO(gongysh) consider the disabled agent's network
fields = ['network_id', 'enable_dhcp'] fields = ['network_id', 'enable_dhcp']
subnets = plugin.get_subnets(context, fields=fields) subnets = plugin.get_subnets(context, fields=fields)
net_ids = set(s['network_id'] for s in subnets net_ids = set(s['network_id'] for s in subnets
@ -113,6 +112,8 @@ class ChanceScheduler(object):
context, [net_id], active=True) context, [net_id], active=True)
if len(agents) >= agents_per_network: if len(agents) >= agents_per_network:
continue continue
if any(dhcp_agent.id == agent.id for agent in agents):
continue
binding = agentschedulers_db.NetworkDhcpAgentBinding() binding = agentschedulers_db.NetworkDhcpAgentBinding()
binding.dhcp_agent = dhcp_agent binding.dhcp_agent = dhcp_agent
binding.network_id = net_id binding.network_id = net_id

View File

@ -291,6 +291,17 @@ class OvsAgentSchedulerTestCase(test_l3_plugin.L3NatTestCaseMixin,
self.assertEqual(2, num_hosta_nets) self.assertEqual(2, num_hosta_nets)
self.assertEqual(2, num_hostc_nets) self.assertEqual(2, num_hostc_nets)
def test_network_auto_schedule_restart_dhcp_agent(self):
cfg.CONF.set_override('dhcp_agents_per_network', 2)
with self.subnet() as sub1:
dhcp_rpc = dhcp_rpc_base.DhcpRpcCallbackMixin()
self._register_agent_states()
dhcp_rpc.get_active_networks(self.adminContext, host=DHCP_HOSTA)
dhcp_rpc.get_active_networks(self.adminContext, host=DHCP_HOSTA)
dhcp_agents = self._list_dhcp_agents_hosting_network(
sub1['subnet']['network_id'])
self.assertEqual(1, len(dhcp_agents['agents']))
def test_network_auto_schedule_with_hosted(self): def test_network_auto_schedule_with_hosted(self):
# one agent hosts all the networks, other hosts none # one agent hosts all the networks, other hosts none
cfg.CONF.set_override('allow_overlapping_ips', True) cfg.CONF.set_override('allow_overlapping_ips', True)
@ -563,6 +574,13 @@ class OvsAgentSchedulerTestCase(test_l3_plugin.L3NatTestCaseMixin,
self.assertEqual(1, len(l3_agents['agents'])) self.assertEqual(1, len(l3_agents['agents']))
self.assertEqual(L3_HOSTA, l3_agents['agents'][0]['host']) self.assertEqual(L3_HOSTA, l3_agents['agents'][0]['host'])
def test_router_auto_schedule_restart_l3_agent(self):
with self.router():
l3_rpc = l3_rpc_base.L3RpcCallbackMixin()
self._register_agent_states()
l3_rpc.sync_routers(self.adminContext, host=L3_HOSTA)
l3_rpc.sync_routers(self.adminContext, host=L3_HOSTA)
def test_router_auto_schedule_with_hosted_2(self): def test_router_auto_schedule_with_hosted_2(self):
# one agent hosts one router # one agent hosts one router
l3_rpc = l3_rpc_base.L3RpcCallbackMixin() l3_rpc = l3_rpc_base.L3RpcCallbackMixin()