From cd524065e2ac4f48d8b9810fa9735f0fd925c4d8 Mon Sep 17 00:00:00 2001 From: Tu Hong Jun Date: Thu, 20 Aug 2015 14:08:07 +0800 Subject: [PATCH] Changed filter field to router_id The get_sync_interfaces query will always return all router ports from database even it is supposed to query specific ones that belong to a certain router. In large L3 scale environment with number of route ports in place, this would lag the response time for adding router interface and router L3 agent binding. Closes-Bug: #1489671 Change-Id: Ib78ca766f91783ad2ecca5b728c31602b4ed15d8 --- neutron/db/l3_db.py | 2 +- neutron/tests/unit/extensions/test_l3.py | 36 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index ebd7465e8..99eba12d2 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -1173,7 +1173,7 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase): return [] qry = context.session.query(RouterPort) qry = qry.filter( - Router.id.in_(router_ids), + RouterPort.router_id.in_(router_ids), RouterPort.port_type.in_(device_owners) ) diff --git a/neutron/tests/unit/extensions/test_l3.py b/neutron/tests/unit/extensions/test_l3.py index 77e55682b..5a4ba441f 100644 --- a/neutron/tests/unit/extensions/test_l3.py +++ b/neutron/tests/unit/extensions/test_l3.py @@ -2501,6 +2501,42 @@ class L3AgentDbTestCaseBase(L3NatTestCaseMixin): wanted_subnetid = p['port']['fixed_ips'][0]['subnet_id'] self.assertEqual(wanted_subnetid, subnet_id) + def test_l3_agent_sync_interfaces(self): + """Test L3 interfaces query return valid result""" + with self.router() as router1, self.router() as router2: + with self.port() as port1, self.port() as port2: + self._router_interface_action('add', + router1['router']['id'], + None, + port1['port']['id']) + self._router_interface_action('add', + router2['router']['id'], + None, + port2['port']['id']) + admin_ctx = context.get_admin_context() + router1_id = router1['router']['id'] + router2_id = router2['router']['id'] + + # Verify if router1 pass in, return only interface from router1 + ifaces = self.plugin._get_sync_interfaces(admin_ctx, + [router1_id]) + self.assertEqual(1, len(ifaces)) + self.assertEqual(router1_id, + ifaces[0]['device_id']) + + # Verify if router1 and router2 pass in, return both interfaces + ifaces = self.plugin._get_sync_interfaces(admin_ctx, + [router1_id, + router2_id]) + self.assertEqual(2, len(ifaces)) + device_list = [i['device_id'] for i in ifaces] + self.assertIn(router1_id, device_list) + self.assertIn(router2_id, device_list) + + #Verify if no router pass in, return empty list + ifaces = self.plugin._get_sync_interfaces(admin_ctx, None) + self.assertEqual(0, len(ifaces)) + def test_l3_agent_routers_query_ignore_interfaces_with_moreThanOneIp(self): with self.router() as r: with self.subnet(cidr='9.0.1.0/24') as subnet: -- 2.45.2