From 7e3cef2d7b6bb839c399ce8730153b6fa7076d96 Mon Sep 17 00:00:00 2001 From: gongysh Date: Thu, 23 May 2013 11:45:49 +0800 Subject: [PATCH] avoid auto scheduling one dhcp agent twice. Bug #1183173 Change-Id: Iff7b23faae50e6736b253ca5a2b1280451127200 --- quantum/scheduler/dhcp_agent_scheduler.py | 3 ++- .../unit/openvswitch/test_agent_scheduler.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/quantum/scheduler/dhcp_agent_scheduler.py b/quantum/scheduler/dhcp_agent_scheduler.py index 9bcadd7ed..53496aff4 100644 --- a/quantum/scheduler/dhcp_agent_scheduler.py +++ b/quantum/scheduler/dhcp_agent_scheduler.py @@ -100,7 +100,6 @@ class ChanceScheduler(object): dhcp_agent.heartbeat_timestamp): LOG.warn(_('DHCP agent %s is not active'), dhcp_agent.id) continue - #TODO(gongysh) consider the disabled agent's network fields = ['network_id', 'enable_dhcp'] subnets = plugin.get_subnets(context, fields=fields) net_ids = set(s['network_id'] for s in subnets @@ -113,6 +112,8 @@ class ChanceScheduler(object): context, [net_id], active=True) if len(agents) >= agents_per_network: continue + if any(dhcp_agent.id == agent.id for agent in agents): + continue binding = agentschedulers_db.NetworkDhcpAgentBinding() binding.dhcp_agent = dhcp_agent binding.network_id = net_id diff --git a/quantum/tests/unit/openvswitch/test_agent_scheduler.py b/quantum/tests/unit/openvswitch/test_agent_scheduler.py index c28e09d7f..30ab21c46 100644 --- a/quantum/tests/unit/openvswitch/test_agent_scheduler.py +++ b/quantum/tests/unit/openvswitch/test_agent_scheduler.py @@ -291,6 +291,17 @@ class OvsAgentSchedulerTestCase(test_l3_plugin.L3NatTestCaseMixin, self.assertEqual(2, num_hosta_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): # one agent hosts all the networks, other hosts none 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(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): # one agent hosts one router l3_rpc = l3_rpc_base.L3RpcCallbackMixin() -- 2.45.2