diff --git a/neutron/db/l3_agentschedulers_db.py b/neutron/db/l3_agentschedulers_db.py index 5bcbe3cce80..08a8afb1591 100644 --- a/neutron/db/l3_agentschedulers_db.py +++ b/neutron/db/l3_agentschedulers_db.py @@ -15,6 +15,7 @@ from neutron_lib.api import extensions from neutron_lib import constants +from neutron_lib.exceptions import agent as agent_exc from neutron_lib.plugins import constants as plugin_constants from neutron_lib.plugins import directory from oslo_config import cfg @@ -283,8 +284,11 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase, return self.get_sync_data(context, router_ids=router_ids, active=True) def list_router_ids_on_host(self, context, host, router_ids=None): - agent = self._get_agent_by_type_and_host( - context, constants.AGENT_TYPE_L3, host) + try: + agent = self._get_agent_by_type_and_host( + context, constants.AGENT_TYPE_L3, host) + except agent_exc.AgentNotFoundByTypeHost: + return [] if not agentschedulers_db.services_available(agent.admin_state_up): return [] return self._get_router_ids_for_agent(context, agent, router_ids) diff --git a/neutron/tests/unit/db/test_agentschedulers_db.py b/neutron/tests/unit/db/test_agentschedulers_db.py index 26de49a8318..850c865b02a 100644 --- a/neutron/tests/unit/db/test_agentschedulers_db.py +++ b/neutron/tests/unit/db/test_agentschedulers_db.py @@ -269,6 +269,12 @@ class OvsAgentSchedulerTestCase(OvsAgentSchedulerTestCaseBase): agents = self._list_agents() self.assertEqual(4, len(agents['agents'])) + def test_list_router_ids_on_host_no_l3_agent(self): + l3_rpc_cb = l3_rpc.L3RpcCallback() + self.assertEqual( + [], + l3_rpc_cb.get_router_ids(self.adminContext, host="fake host")) + def test_network_scheduling_on_network_creation(self): self._register_agent_states() with self.network() as net: