]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Always return iterables in L3 get_candidates
authorKevin Benton <blak111@gmail.com>
Fri, 4 Sep 2015 03:25:57 +0000 (20:25 -0700)
committerKevin Benton <blak111@gmail.com>
Tue, 15 Sep 2015 23:25:45 +0000 (16:25 -0700)
The caller of this function expects iterables.

Closes-Bug: #1494996
Change-Id: I3d103e63f4e127a77268502415c0ddb0d804b54a

neutron/scheduler/l3_agent_scheduler.py
neutron/tests/unit/scheduler/test_l3_agent_scheduler.py

index e41a34968d77e024ae161044b81b5f9546ede193..844c640bb4152f58d7f5e5da4ed8011935b15969 100644 (file)
@@ -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)
index f1156c456970ed5fb333a012c905394f274398fe..9bb0cc60ddc632c3020c5f345eaea48982ec5658 100644 (file)
@@ -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):