From: Ed Bak Date: Mon, 9 Feb 2015 23:13:18 +0000 (+0000) Subject: Return from check_ports_exist_on_l3agent if no subnet found X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=760fe6a8fabc921e75367b5f02bab4fc326b8115;p=openstack-build%2Fneutron-build.git Return from check_ports_exist_on_l3agent if no subnet found The call to get_subnet_ids_on_router can return an empty list. If the subnet_ids list is empty, the subsequent call to get the ports on a subnet returns all ports. If this occurs when doing a remove_router_interface, the performance of a remove_router_interface degrades significantly. This change returns immediately from check_ports_exist_on_l3agents if no subnet is found. A new unit test has been added to cover the specific case of returning immediately without calling get_ports when a remove_router_interface operation is performed. Change-Id: I247d3bae152ab4f8ab7e00bd24d878eb08dca1ba Closes-Bug: #1420032 Depends-On: I15bbf16fd4378c6431e9da8942d0968e7a012a91 --- diff --git a/neutron/db/l3_agentschedulers_db.py b/neutron/db/l3_agentschedulers_db.py index cbcee9a47..931436bdd 100644 --- a/neutron/db/l3_agentschedulers_db.py +++ b/neutron/db/l3_agentschedulers_db.py @@ -375,6 +375,8 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, ports on the host, running the input l3agent. """ subnet_ids = self.get_subnet_ids_on_router(context, router_id) + if not subnet_ids: + return False core_plugin = manager.NeutronManager.get_plugin() filter = {'fixed_ips': {'subnet_id': subnet_ids}} diff --git a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py index 267eceefa..a68d2e708 100644 --- a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py @@ -671,6 +671,17 @@ class L3SchedulerTestBaseMixin(object): l3_agent, router['id']) self.assertFalse(val) + def test_check_ports_exist_on_l3agent_if_no_subnets_then_return(self): + l3_agent, router = self._prepare_check_ports_exist_tests() + with mock.patch.object(manager.NeutronManager, + 'get_plugin') as getp: + getp.return_value = self.plugin + # no subnets and operation is remove_router_interface, + # so return immediately without calling get_ports + self.check_ports_exist_on_l3agent(self.adminContext, + l3_agent, router['id']) + self.assertFalse(self.plugin.get_ports.called) + def test_check_ports_exist_on_l3agent_no_subnet_match(self): l3_agent, router = self._prepare_check_ports_exist_tests() # no matching subnet @@ -688,7 +699,7 @@ class L3SchedulerTestBaseMixin(object): 'device_owner': 'compute:', 'id': 1234} self.plugin.get_ports.return_value = [port] - self.plugin.get_subnet_ids_on_router = mock.Mock( + self.get_subnet_ids_on_router = mock.Mock( return_value=[port['subnet_id']]) val = self.check_ports_exist_on_l3agent(self.adminContext, l3_agent, router['id'])