network_get_all_by_host does not return the right networks

Bug #954341 reported by Jason Kölker on 2012-03-13
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Jason Kölker

Bug Description

network_get_all_by_host in the sqlalchemy api should return entries were there is a fixed_ip on that host as well. Since the FK's got removed, this query no longer returns all the right rows.


$ git diff
diff --git a/nova/db/sqlalchemy/ b/nova/db/sqlalchemy/
index 2136dbd..3544023 100644
--- a/nova/db/sqlalchemy/
+++ b/nova/db/sqlalchemy/
@@ -2067,11 +2067,15 @@ def network_get_all_by_instance(context, instance_id):

 def network_get_all_by_host(context, host):
+ session = get_session()
+ fixed_ip_query = model_query(context, models.FixedIp.network_id,
+ session=session).\
+ filter( == host)
     # NOTE(vish): return networks that have host set
     # or that have a fixed ip with host set
     host_filter = or_( == host,
- == host)
- return _network_get_query(context).\
+ return _network_get_query(context, session=session).\

Which emits the following query:

    networks.created_at AS networks_created_at,
    networks.updated_at AS networks_updated_at,
    networks.deleted_at AS networks_deleted_at,
    networks.deleted AS networks_deleted, AS networks_id,
    networks.label AS networks_label,
    networks.injected AS networks_injected,
    networks.cidr AS networks_cidr,
    networks.cidr_v6 AS networks_cidr_v6,
    networks.multi_host AS networks_multi_host,
    networks.gateway_v6 AS networks_gateway_v6,
    networks.netmask_v6 AS networks_netmask_v6,
    networks.netmask AS networks_netmask,
    networks.bridge AS networks_bridge,
    networks.bridge_interface AS networks_bridge_interface,
    networks.gateway AS networks_gateway,
    networks.broadcast AS networks_broadcast,
    networks.dns1 AS networks_dns1,
    networks.dns2 AS networks_dns2,
    networks.vlan AS networks_vlan,
    networks.vpn_public_address AS networks_vpn_public_address,
    networks.vpn_public_port AS networks_vpn_public_port,
    networks.vpn_private_address AS networks_vpn_private_address,
    networks.dhcp_start AS networks_dhcp_start,
    networks.rxtx_base AS networks_rxtx_base,
    networks.project_id AS networks_project_id,
    networks.priority AS networks_priority, AS networks_host,
    networks.uuid AS networks_uuid
FROM networks
WHERE networks.deleted = :deleted_1
AND ( = :host_1 OR IN (SELECT fixed_ips.network_id
                    FROM fixed_ips
                    WHERE fixed_ips.deleted = :deleted_2
                    AND = :host_2))

Changed in nova:
assignee: nobody → Jason Kölker (jason-koelker)
status: New → Confirmed

Fix proposed to branch: master

Changed in nova:
status: Confirmed → In Progress

Submitter: Jenkins
Branch: master

commit c8ad7f7c406b4684391bfd5aa0b309b4d9dafe70
Author: Jason Kölker <email address hidden>
Date: Tue Mar 13 14:14:36 2012 -0500

    Use a FixedIp subquery to find networks by host

    * Fixes LP954341
    * The FK removals missed this FK reference. Updated function to use
        a subquery in the filter

    Change-Id: Ia61d6536deb78e1aa16c5a94956bf919aa3356ba

Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx) on 2012-03-20
Changed in nova:
milestone: none → essex-rc1
status: Fix Committed → Fix Released
Thierry Carrez (ttx) on 2012-04-05
Changed in nova:
milestone: essex-rc1 → 2012.1
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers