]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Only get host data for floating ips on DVR routers
authorCarl Baldwin <carl.baldwin@hp.com>
Wed, 16 Sep 2015 21:53:54 +0000 (21:53 +0000)
committerCarl Baldwin <carl@ecbaldwin.net>
Tue, 22 Sep 2015 19:11:29 +0000 (19:11 +0000)
First, we are only interested in setting the host attribute when
the router is a DVR router.  Second, we don't need to query all of
the ports on the host, we just need to query the ports that are
referenced by the set of floating ips that we already have.

Closes-bug: #1496974
Change-Id: If611de14b2ab77d2eb9ce8c5b307ea6dd4403fe1

neutron/db/l3_dvr_db.py

index 8223e4e89878a54576d694b5448baf97d411367c..4bafc56b225f6d4490348ab998dc90935d361275 100644 (file)
@@ -433,15 +433,22 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
         routers, interfaces, floating_ips = self._get_router_info_list(
             context, router_ids=router_ids, active=active,
             device_owners=l3_const.ROUTER_INTERFACE_OWNERS)
-        port_filter = {portbindings.HOST_ID: [host]}
-        ports = self._core_plugin.get_ports(context, port_filter)
-        port_dict = dict((port['id'], port) for port in ports)
-        # Add the port binding host to the floatingip dictionary
-        for fip in floating_ips:
-            vm_port = port_dict.get(fip['port_id'], None)
-            if vm_port:
-                fip['host'] = self._get_vm_port_hostid(context, fip['port_id'],
-                                                      port=vm_port)
+        dvr_router_ids = set(router['id'] for router in routers
+                             if is_distributed_router(router))
+        floating_ip_port_ids = [fip['port_id'] for fip in floating_ips
+                                if fip['router_id'] in dvr_router_ids]
+        if floating_ip_port_ids:
+            port_filter = {portbindings.HOST_ID: [host],
+                           'id': floating_ip_port_ids}
+            ports = self._core_plugin.get_ports(context, port_filter)
+            port_dict = dict((port['id'], port) for port in ports)
+            # Add the port binding host to the floatingip dictionary
+            for fip in floating_ips:
+                vm_port = port_dict.get(fip['port_id'], None)
+                if vm_port:
+                    fip['host'] = self._get_vm_port_hostid(context,
+                                                           fip['port_id'],
+                                                           port=vm_port)
         routers_dict = self._process_routers(context, routers)
         self._process_floating_ips_dvr(context, routers_dict,
                                        floating_ips, host, agent)