From d1d4de19d85f961d388c91e70f31b3bafec418c5 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Thu, 3 Sep 2015 20:25:57 -0700 Subject: [PATCH] Always return iterables in L3 get_candidates The caller of this function expects iterables. Closes-Bug: #1494996 Change-Id: I3d103e63f4e127a77268502415c0ddb0d804b54a --- neutron/scheduler/l3_agent_scheduler.py | 4 ++-- .../tests/unit/scheduler/test_l3_agent_scheduler.py | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/neutron/scheduler/l3_agent_scheduler.py b/neutron/scheduler/l3_agent_scheduler.py index e41a34968..844c640bb 100644 --- a/neutron/scheduler/l3_agent_scheduler.py +++ b/neutron/scheduler/l3_agent_scheduler.py @@ -174,12 +174,12 @@ class L3Scheduler(object): ' by L3 agent %(agent_id)s', {'router_id': sync_router['id'], 'agent_id': l3_agents[0]['id']}) - return + return [] active_l3_agents = plugin.get_l3_agents(context, active=True) if not active_l3_agents: LOG.warn(_LW('No active L3 agents')) - return + return [] new_l3agents = plugin.get_l3_agent_candidates(context, sync_router, active_l3_agents) diff --git a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py index f1156c456..9bb0cc60d 100644 --- a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py @@ -268,6 +268,17 @@ class L3SchedulerBaseTestCase(base.BaseTestCase): def test__bind_routers_ha_no_binding(self): self._test__bind_routers_ha(has_binding=False) + def test__get_candidates_iterable_on_early_returns(self): + plugin = mock.MagicMock() + # non-distributed router already hosted + plugin.get_l3_agents_hosting_routers.return_value = [{'id': 'a1'}] + router = {'distributed': False, 'id': 'falafel'} + iter(self.scheduler._get_candidates(plugin, mock.MagicMock(), router)) + # distributed router but no agents + router['distributed'] = True + plugin.get_l3_agents.return_value = [] + iter(self.scheduler._get_candidates(plugin, mock.MagicMock(), router)) + class L3SchedulerBaseMixin(object): -- 2.45.2