From d55845236decbbc514d6f7827e13c7774775e298 Mon Sep 17 00:00:00 2001 From: Oleg Bondarev Date: Fri, 15 Jan 2016 11:37:00 +0300 Subject: [PATCH] Filter by device_owner instead of iterating by all subnet ports Optimization in _generate_arp_table_and_notify_agent() Change-Id: Id19af911d5ae4e62971abe7501c2c60ea2fc99a9 --- neutron/db/l3_dvr_db.py | 20 ++++++++++---------- neutron/tests/unit/db/test_l3_dvr_db.py | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index 5d34bb8b0d1..53479fce27a 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -689,18 +689,18 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, """Generates the arp table entry and notifies the l3 agent.""" ip_address = fixed_ip['ip_address'] subnet = fixed_ip['subnet_id'] - filters = {'fixed_ips': {'subnet_id': [subnet]}} + filters = {'fixed_ips': {'subnet_id': [subnet]}, + 'device_owner': [l3_const.DEVICE_OWNER_DVR_INTERFACE]} ports = self._core_plugin.get_ports(context, filters=filters) for port in ports: - if port['device_owner'] == l3_const.DEVICE_OWNER_DVR_INTERFACE: - router_id = port['device_id'] - router_dict = self._get_router(context, router_id) - if router_dict.extra_attributes.distributed: - arp_table = {'ip_address': ip_address, - 'mac_address': mac_address, - 'subnet_id': subnet} - notifier(context, router_id, arp_table) - return + router_id = port['device_id'] + router_dict = self._get_router(context, router_id) + if router_dict.extra_attributes.distributed: + arp_table = {'ip_address': ip_address, + 'mac_address': mac_address, + 'subnet_id': subnet} + notifier(context, router_id, arp_table) + return def update_arp_entry_for_dvr_service_port( self, context, port_dict, action): diff --git a/neutron/tests/unit/db/test_l3_dvr_db.py b/neutron/tests/unit/db/test_l3_dvr_db.py index 84b772f8358..70750809e32 100644 --- a/neutron/tests/unit/db/test_l3_dvr_db.py +++ b/neutron/tests/unit/db/test_l3_dvr_db.py @@ -609,7 +609,7 @@ class L3DvrTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): 'device_owner': l3_const.DEVICE_OWNER_DVR_INTERFACE, 'device_id': 'dvr_router_id' } - plugin.get_ports.return_value = [port, dvr_port] + plugin.get_ports.return_value = [dvr_port] grtr.return_value = dvr_router dvr_router.extra_attributes.distributed = True self.mixin.update_arp_entry_for_dvr_service_port(