Handle AgentNotFoundByTypeHost exception properly

During listing router_ids on host it is possible that on some hosts
there are no L3 agents.
In such case AgentNotFoundByTypeHost exception is raised in
neutron.db.agents_db module in _get_agent_by_type_and_host() method.
Now this exception is properly handled during listing routers on host.

Change-Id: Ia5ff1b57ef63c98b4ada4f2d46c45336e413be3d
Closes-Bug: #1737917
This commit is contained in:
Sławek Kapłoński 2018-03-30 10:24:59 +02:00 committed by Slawek Kaplonski
parent 5f306a8b24
commit 7b0f6330d6
2 changed files with 12 additions and 2 deletions

View File

@ -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)

View File

@ -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: