]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Replace unnecessary call to get_sync_routers
authorKevin Benton <blak111@gmail.com>
Fri, 17 Apr 2015 11:51:26 +0000 (04:51 -0700)
committerKevin Benton <blak111@gmail.com>
Sat, 25 Apr 2015 06:32:23 +0000 (23:32 -0700)
Replaces a call to get_sync_routers with a single-column
router DB query in a method that doesn't use any of the
gateway information get_sync_routers spends extra
time populating.

Change-Id: I35eae975209316aad6b2c97c909dce385729864d
Partial-Bug: #1445412

neutron/db/l3_dvr_db.py
neutron/tests/unit/db/test_l3_dvr_db.py

index 9372b251e7e8712b9e3e460498f3961c4c2ee37b..678dd39ac9a194f4999e5e949c3f8d63259c9fb7 100644 (file)
@@ -490,13 +490,17 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
         if ports:
             return ports[0]
 
+    def _get_router_ids(self, context):
+        """Function to retrieve router IDs for a context without joins"""
+        query = self._model_query(context, l3_db.Router.id)
+        return [row[0] for row in query]
+
     def _check_fips_availability_on_host_ext_net(
         self, context, host_id, fip_ext_net_id):
         """Query all floating_ips and filter on host and external net."""
         fip_count_on_host = 0
         with context.session.begin(subtransactions=True):
-            routers = self._get_sync_routers(context, router_ids=None)
-            router_ids = [router['id'] for router in routers]
+            router_ids = self._get_router_ids(context)
             floating_ips = self._get_sync_floating_ips(context, router_ids)
             # Check for the active floatingip in the host
             for fip in floating_ips:
index 46fa775179bfdfcfb9fa3375ce1f797cbc6386e0..cf76942ace1febc3d2ad0350d123515290182fd4 100644 (file)
@@ -19,6 +19,7 @@ import mock
 from neutron.common import constants as l3_const
 from neutron.common import exceptions
 from neutron import context
+from neutron.db import common_db_mixin
 from neutron.db import l3_dvr_db
 from neutron import manager
 from neutron.openstack.common import uuidutils
@@ -46,6 +47,19 @@ class L3DvrTestCase(testlib_api.SqlTestCase):
         result = self._create_router(router)
         self.assertEqual(expected, result.extra_attributes['distributed'])
 
+    def test_router_id_query(self):
+        # need to create an object that has the common db method required
+        class DVRwithCommon(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
+                            common_db_mixin.CommonDbMixin):
+            pass
+        self.mixin = DVRwithCommon()
+        routers = [self._create_router({'name': '%s' % x,
+                                        'admin_state_up': True})
+                   for x in range(10)]
+        expected = [router['id'] for router in routers]
+        router_ids = self.mixin._get_router_ids(self.ctx)
+        self.assertEqual(sorted(expected), sorted(router_ids))
+
     def test_create_router_db_default(self):
         self._test__create_router_db(expected=False)