Merge "Check compatibility when auto schedule ha routers" into stable/liberty

This commit is contained in:
Jenkins 2016-07-29 03:48:27 +00:00 committed by Gerrit Code Review
commit cc6c2029ba
2 changed files with 46 additions and 10 deletions

View File

@ -307,16 +307,22 @@ class L3Scheduler(object):
scheduled = False
admin_ctx = context.elevated()
for router_id, tenant_id, agents in routers_agents:
max_agents_not_reached = (
not self.max_ha_agents or agents < self.max_ha_agents)
if max_agents_not_reached:
if not self._router_has_binding(admin_ctx, router_id,
agent.id):
self.create_ha_port_and_bind(plugin, admin_ctx,
router_id, tenant_id,
agent)
scheduled = True
underscheduled_router_ids = [
router_id for router_id, tenant_id, agents in routers_agents
if (not self.max_ha_agents or agents < self.max_ha_agents)
]
underscheduled_routers = plugin.get_routers(
context, filters={'id': underscheduled_router_ids})
schedulable_routers = self._get_routers_can_schedule(
admin_ctx, plugin, underscheduled_routers, agent)
for router in schedulable_routers:
if not self._router_has_binding(admin_ctx, router['id'],
agent.id):
self.create_ha_port_and_bind(plugin, admin_ctx,
router['id'],
router['tenant_id'],
agent)
scheduled = True
return scheduled

View File

@ -2033,6 +2033,36 @@ class L3HAChanceSchedulerTestCase(L3HATestCaseMixin):
def test_auto_schedule_all_routers_when_agent_added(self):
self._auto_schedule_when_agent_added(False)
def test_auto_schedule_ha_router_when_incompatible_agent_exist(self):
handle_internal_only_routers_agent = helpers.register_l3_agent(
'host_3', constants.L3_AGENT_MODE_LEGACY, internal_only=False)
router = self._create_ha_router()
self.plugin.schedule_router(self.adminContext, router['id'])
self.plugin.auto_schedule_routers(
self.adminContext, handle_internal_only_routers_agent.host, [])
agents = self.plugin.get_l3_agents_hosting_routers(
self.adminContext, [router['id']],
admin_state_up=True)
agent_ids = [agent['id'] for agent in agents]
self.assertEqual(2, len(agents))
self.assertNotIn(handle_internal_only_routers_agent.id, agent_ids)
def test_auto_schedule_ha_router_when_dvr_agent_exist(self):
dvr_agent = helpers.register_l3_agent(
HOST_DVR, constants.L3_AGENT_MODE_DVR)
router = self._create_ha_router()
self.plugin.schedule_router(self.adminContext, router['id'])
self.plugin.auto_schedule_routers(self.adminContext, dvr_agent.host,
[])
agents = self.plugin.get_l3_agents_hosting_routers(
self.adminContext, [router['id']],
admin_state_up=True)
agent_ids = [agent['id'] for agent in agents]
self.assertEqual(2, len(agents))
self.assertNotIn(dvr_agent.id, agent_ids)
def _auto_schedule_when_agent_added(self, specific_router):
router = self._create_ha_router()
self.plugin.schedule_router(self.adminContext, router['id'])