Merge "Bring back dvr routers autoscheduling"

This commit is contained in:
Jenkins 2016-02-09 21:58:23 +00:00 committed by Gerrit Code Review
commit d1cc83a6fe
4 changed files with 23 additions and 31 deletions

@ -91,29 +91,19 @@ class L3Scheduler(object):
context, filters={'id': unscheduled_router_ids})
return []
def _get_routers_to_schedule(self, context, plugin,
router_ids=None, exclude_distributed=False):
def _get_routers_to_schedule(self, context, plugin, router_ids=None):
"""Verify that the routers specified need to be scheduled.
:param context: the context
:param plugin: the core plugin
:param router_ids: the list of routers to be checked for scheduling
:param exclude_distributed: whether or not to consider dvr routers
:returns: the list of routers to be scheduled
"""
if router_ids is not None:
routers = plugin.get_routers(context, filters={'id': router_ids})
unscheduled_routers = self._filter_unscheduled_routers(
context, plugin, routers)
return self._filter_unscheduled_routers(context, plugin, routers)
else:
unscheduled_routers = self._get_unscheduled_routers(context,
plugin)
if exclude_distributed:
unscheduled_routers = [
r for r in unscheduled_routers if not r.get('distributed')
]
return unscheduled_routers
return self._get_unscheduled_routers(context, plugin)
def _get_routers_can_schedule(self, context, plugin, routers, l3_agent):
"""Get the subset of routers that can be scheduled on the L3 agent."""
@ -143,11 +133,8 @@ class L3Scheduler(object):
if not l3_agent:
return False
# NOTE(armando-migliaccio): DVR routers should not be auto
# scheduled because auto-scheduling may interfere with the
# placement rules for IR and SNAT namespaces.
unscheduled_routers = self._get_routers_to_schedule(
context, plugin, router_ids, exclude_distributed=True)
context, plugin, router_ids)
if not unscheduled_routers:
if utils.is_extension_supported(
plugin, constants.L3_HA_MODE_EXT_ALIAS):

@ -299,3 +299,6 @@ class L3DvrHATestCase(test_l3_dvr_router_plugin.L3DvrTestCase):
def test__get_router_ids_for_agent(self):
self.skipTest('Valid for DVR-only routers')
def test_router_auto_scheduling(self):
self.skipTest('Valid for DVR-only routers')

@ -14,6 +14,7 @@
import mock
from neutron.api.rpc.handlers import l3_rpc
from neutron.api.v2 import attributes
from neutron.common import constants
from neutron.common import topics
@ -900,3 +901,18 @@ class L3DvrTestCase(ml2_test_base.ML2TestFramework):
l3_notifier.router_removed_from_agent.assert_called_once_with(
self.context, router['id'], HOST1)
def test_router_auto_scheduling(self):
router = self._create_router()
agents = self.l3_plugin.list_l3_agents_hosting_router(
self.context, router['id'])
# router is not scheduled yet
self.assertEqual([], agents['agents'])
l3_rpc_handler = l3_rpc.L3RpcCallback()
# router should be auto scheduled once l3 agent requests router ids
l3_rpc_handler.get_router_ids(self.context, self.l3_agent['host'])
agents = self.l3_plugin.list_l3_agents_hosting_router(
self.context, router['id'])
self.assertEqual(1, len(agents['agents']))
self.assertEqual(self.l3_agent['id'], agents['agents'][0]['id'])

@ -202,20 +202,6 @@ class L3SchedulerBaseTestCase(base.BaseTestCase):
mock_get.assert_called_once_with(mock.ANY, self.plugin)
self.assertEqual(expected_routers, unscheduled_routers)
def test__get_routers_to_schedule_exclude_distributed(self):
routers = [
{'id': 'foo_router1', 'distributed': True}, {'id': 'foo_router_2'}
]
expected_routers = [{'id': 'foo_router_2'}]
with mock.patch.object(self.scheduler,
'_get_unscheduled_routers') as mock_get:
mock_get.return_value = routers
unscheduled_routers = self.scheduler._get_routers_to_schedule(
mock.ANY, self.plugin,
router_ids=None, exclude_distributed=True)
mock_get.assert_called_once_with(mock.ANY, self.plugin)
self.assertEqual(expected_routers, unscheduled_routers)
def _test__get_routers_can_schedule(self, routers, agent, target_routers):
self.plugin.get_l3_agent_candidates.return_value = agent
result = self.scheduler._get_routers_can_schedule(