Remove double queries in l3 DB get methods

Two frequently called functions were querying the routerport table
and the corresponding ports just to get the port ID. Then they were
calling get_ports again with those port IDs, resulting in two queries
to the port table when there should have only been one.

This eliminates the second call to get_ports since all of the necessary
data hase been retrieved from the port table.

Change-Id: I806e9c380b7de048fe084b2baf4b6f92ab0edf6b
Partial-Bug: #1445412
(cherry picked from commit 3310c3c3d4)
This commit is contained in:
Kevin Benton 2015-04-17 04:28:58 -07:00 committed by Kevin Benton
parent 69fd2ef251
commit 4a69a64c8a
2 changed files with 7 additions and 12 deletions

View File

@ -989,10 +989,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase):
RouterPort.port_type.in_(device_owners)
)
# TODO(markmcclain): This is suboptimal but was left to reduce
# changeset size since it is late in cycle
ports = [rp.port.id for rp in qry]
interfaces = self._core_plugin.get_ports(context, {'id': ports})
interfaces = [self._core_plugin._make_port_dict(rp.port, None)
for rp in qry]
if interfaces:
self._populate_subnet_for_ports(context, interfaces)
return interfaces

View File

@ -272,10 +272,8 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
l3_db.RouterPort.port_type == DEVICE_OWNER_DVR_SNAT
)
# TODO(markmcclain): This is suboptimal but was left to reduce
# changeset size since it is late in cycle
ports = [rp.port.id for rp in qry]
interfaces = self._core_plugin.get_ports(context, {'id': ports})
interfaces = [self._core_plugin._make_port_dict(rp.port, None)
for rp in qry]
LOG.debug("Return the SNAT ports: %s", interfaces)
if interfaces:
self._populate_subnet_for_ports(context, interfaces)
@ -463,16 +461,15 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
def get_snat_interface_ports_for_router(self, context, router_id):
"""Return all existing snat_router_interface ports."""
# TODO(markmcclain): This is suboptimal but was left to reduce
# changeset size since it is late in cycle
qry = context.session.query(l3_db.RouterPort)
qry = qry.filter_by(
router_id=router_id,
port_type=DEVICE_OWNER_DVR_SNAT
)
ports = [rp.port.id for rp in qry]
return self._core_plugin.get_ports(context, {'id': ports})
ports = [self._core_plugin._make_port_dict(rp.port, None)
for rp in qry]
return ports
def add_csnat_router_interface_port(
self, context, router, network_id, subnet_id, do_pop=True):