]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
avoid auto scheduling one dhcp agent twice.
authorgongysh <gongysh@linux.vnet.ibm.com>
Thu, 23 May 2013 03:45:49 +0000 (11:45 +0800)
committergongysh <gongysh@linux.vnet.ibm.com>
Thu, 23 May 2013 14:54:28 +0000 (22:54 +0800)
Bug #1183173

Change-Id: Iff7b23faae50e6736b253ca5a2b1280451127200

quantum/scheduler/dhcp_agent_scheduler.py
quantum/tests/unit/openvswitch/test_agent_scheduler.py

index 9bcadd7edec24a0fa0a591381d81b69fad9d8a68..53496aff44c602c74d794e002ab79bcd426db5f0 100644 (file)
@@ -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
index c28e09d7fc926bb5562855c196f77c39e41b3c12..30ab21c46d0cdadf6ca905d8ae7c03167c5044d2 100644 (file)
@@ -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()