From: Kevin Benton Date: Fri, 17 Apr 2015 12:10:26 +0000 (-0700) Subject: Get all interfaces for get_snat_sync_interfaces X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=26284228dfc3c5f121f869dd6b2d2a492afaf659;p=openstack-build%2Fneutron-build.git Get all interfaces for get_snat_sync_interfaces The get_snat_sync_interfaces method was being called for each router individually during a sync, which resulted in a new query to the database. This patch eliminates that waste by querying for the snat interfaces for all of the routers in the list at once. Change-Id: I1e44a0cf15a70632e8b62ac89ce807a7a457747d Partial-Bug: #1445412 --- diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index 678dd39ac..3d15e9698 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -11,6 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. +import collections from oslo_config import cfg from oslo_log import log as logging @@ -358,9 +359,10 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, l3_db.RouterPort.router_id.in_(router_ids), l3_db.RouterPort.port_type == DEVICE_OWNER_DVR_SNAT ) - - interfaces = [self._core_plugin._make_port_dict(rp.port, None) - for rp in qry] + interfaces = collections.defaultdict(list) + for rp in qry: + interfaces[rp.router_id].append( + self._core_plugin._make_port_dict(rp.port, None)) LOG.debug("Return the SNAT ports: %s", interfaces) return interfaces @@ -395,12 +397,12 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, def _process_routers(self, context, routers): routers_dict = {} + snat_intfs_by_router_id = self._get_snat_sync_interfaces( + context, [r['id'] for r in routers]) for router in routers: routers_dict[router['id']] = router - router_ids = [router['id']] if router['gw_port_id']: - snat_router_intfs = self._get_snat_sync_interfaces(context, - router_ids) + snat_router_intfs = snat_intfs_by_router_id[router['id']] LOG.debug("SNAT ports returned: %s ", snat_router_intfs) router[SNAT_ROUTER_INTF_KEY] = snat_router_intfs return routers_dict