Skip to content

Commit

Permalink
Merge "Bring back dvr routers autoscheduling"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Feb 9, 2016
2 parents 625cb51 + 6fad8d3 commit d1cc83a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
21 changes: 4 additions & 17 deletions neutron/scheduler/l3_agent_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,19 @@ def _get_unscheduled_routers(self, context, plugin):
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."""
Expand Down Expand Up @@ -143,11 +133,8 @@ def auto_schedule_routers(self, plugin, context, host, router_ids):
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,6 @@ def test_update_router_db_centralized_to_distributed(self):

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')
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -900,3 +901,18 @@ def test_remove_router_interface(self):

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'])
14 changes: 0 additions & 14 deletions neutron/tests/unit/scheduler/test_l3_agent_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,6 @@ def test__get_routers_to_schedule_without_router_ids(self):
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(
Expand Down

0 comments on commit d1cc83a

Please sign in to comment.