OpenStack Compute (Nova)

network_get_all_by_host does not return the right networks

Reported by Jason Kölker on 2012-03-13
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Undecided
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.

Proposed:

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

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

Which emits the following query:

SELECT
    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,
    networks.id 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,
    networks.host AS networks_host,
    networks.uuid AS networks_uuid
FROM networks
WHERE networks.deleted = :deleted_1
AND (
    networks.host = :host_1 OR
    networks.id IN (SELECT fixed_ips.network_id
                    FROM fixed_ips
                    WHERE fixed_ips.deleted = :deleted_2
                    AND fixed_ips.host = :host_2))

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

Fix proposed to branch: master
Review: https://review.openstack.org/5282

Changed in nova:
status: Confirmed → In Progress

Reviewed: https://review.openstack.org/5282
Committed: http://github.com/openstack/nova/commit/c8ad7f7c406b4684391bfd5aa0b309b4d9dafe70
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