From: ZhiQiang Fan Date: Wed, 18 Sep 2013 17:53:44 +0000 (+0800) Subject: Ensure router exists when auto_schedule_routers X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3e1116eb0f1d94530707cd6ef4b37f17e9a13918;p=openstack-build%2Fneutron-build.git 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 --- 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()