From 3e1116eb0f1d94530707cd6ef4b37f17e9a13918 Mon Sep 17 00:00:00 2001 From: ZhiQiang Fan Date: Thu, 19 Sep 2013 01:53:44 +0800 Subject: [PATCH] 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 --- neutron/scheduler/l3_agent_scheduler.py | 2 +- .../tests/unit/openvswitch/test_agent_scheduler.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/neutron/scheduler/l3_agent_scheduler.py b/neutron/scheduler/l3_agent_scheduler.py index e98b92894..69af861b7 100644 --- a/neutron/scheduler/l3_agent_scheduler.py +++ b/neutron/scheduler/l3_agent_scheduler.py @@ -98,7 +98,7 @@ class ChanceScheduler(object): candidates = plugin.get_l3_agent_candidates(router, [l3_agent]) if not candidates: 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: LOG.warn(_('No routers compatible with L3 agent configuration' ' on host %s'), host) diff --git a/neutron/tests/unit/openvswitch/test_agent_scheduler.py b/neutron/tests/unit/openvswitch/test_agent_scheduler.py index 560efc605..6895d3ccc 100644 --- a/neutron/tests/unit/openvswitch/test_agent_scheduler.py +++ b/neutron/tests/unit/openvswitch/test_agent_scheduler.py @@ -576,6 +576,19 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): self.assertEqual(1, num_before_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): with self.router() as router: l3_rpc = l3_rpc_base.L3RpcCallbackMixin()