[sqlalchemy-20] query.join should define one table/column per call

The method ``get_router_for_floatingip`` query needs to define a join
clausule per table or column to be joined.

The expected query is the following one:
  SELECT DISTINCT routerports.router_id AS routerports_router_id,
  ipallocations.ip_address AS ipallocations_ip_address

  FROM routerports
    JOIN ports ON ports.id = routerports.port_id
    JOIN ipallocations ON ports.id = ipallocations.port_id
    JOIN ports AS gw_port ON gw_port.device_id = routerports.router_id

  WHERE ports.network_id = ?
    AND routerports.port_type IN (XXX)
    AND ipallocations.subnet_id = ?
    AND gw_port.network_id = ?
    AND gw_port.device_owner = ?

The goal is to retrieve the router that matches the GW IP, that is in
the same subnet and network as provided.

Closes-Bug: #2012643

Change-Id: Id054ffaca17153ff470b6bc91f7c3da4f7bf0fdc
This commit is contained in:
Rodolfo Alonso Hernandez 2023-03-22 12:51:22 +01:00 committed by Rodolfo Alonso
parent 6e1dbe9781
commit 0a69dd5e3d

View File

@ -1267,7 +1267,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase,
# TODO(lujinluo): Need IPAllocation and Port object
routerport_qry = (context.session.query(
RouterPort.router_id, models_v2.IPAllocation.ip_address).
join(RouterPort.port, models_v2.Port.fixed_ips).
join(RouterPort.port).
join(models_v2.Port.fixed_ips).
filter(models_v2.Port.network_id ==
internal_port['network_id'],
RouterPort.port_type.in_(