Ensure router exists when auto_schedule_routers

Currently, the auto_schedule_routers() accepts parameter router_ids,
which may contain invalid router ids, since we've already filtered
them via plugin.get_routers(), we can directly use that safe object.

Closes-Bug: #1217998
Closes-Bug: #1210877

Change-Id: I6196f16cca65fee4e848173d0a0a10fde967195d
This commit is contained in:
ZhiQiang Fan 2013-09-19 01:53:44 +08:00
parent ae56b4e11e
commit 3e1116eb0f
2 changed files with 14 additions and 1 deletions

View File

@ -98,7 +98,7 @@ class ChanceScheduler(object):
candidates = plugin.get_l3_agent_candidates(router, [l3_agent]) candidates = plugin.get_l3_agent_candidates(router, [l3_agent])
if not candidates: if not candidates:
to_removed_ids.append(router['id']) to_removed_ids.append(router['id'])
router_ids = set(unscheduled_router_ids) - set(to_removed_ids) router_ids = set([r['id'] for r in routers]) - set(to_removed_ids)
if not router_ids: if not router_ids:
LOG.warn(_('No routers compatible with L3 agent configuration' LOG.warn(_('No routers compatible with L3 agent configuration'
' on host %s'), host) ' on host %s'), host)

View File

@ -576,6 +576,19 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase):
self.assertEqual(1, num_before_remove) self.assertEqual(1, num_before_remove)
self.assertEqual(0, num_after_remove) self.assertEqual(0, num_after_remove)
def test_router_auto_schedule_with_invalid_router(self):
with self.router() as router:
l3_rpc = l3_rpc_base.L3RpcCallbackMixin()
self._register_agent_states()
# deleted router
ret_a = l3_rpc.sync_routers(self.adminContext, host=L3_HOSTA,
router_ids=[router['router']['id']])
self.assertFalse(ret_a)
# non-existent router
ret_a = l3_rpc.sync_routers(self.adminContext, host=L3_HOSTA,
router_ids=[uuidutils.generate_uuid()])
self.assertFalse(ret_a)
def test_router_auto_schedule_with_hosted(self): def test_router_auto_schedule_with_hosted(self):
with self.router() as router: with self.router() as router:
l3_rpc = l3_rpc_base.L3RpcCallbackMixin() l3_rpc = l3_rpc_base.L3RpcCallbackMixin()