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
(cherry picked from commit 7b0f6330d6f877f3d2093a64c2bca4c14334574c)
This commit is contained in:
Sławek Kapłoński 2018-03-30 10:24:59 +02:00 committed by Slawek Kaplonski
parent e3ff53e3fc
commit cb0afda244
2 changed files with 12 additions and 2 deletions

View File

@ -29,6 +29,7 @@ from neutron.common import utils as n_utils
from neutron.db import agentschedulers_db
from neutron.db.models import agent as agent_model
from neutron.db.models import l3agent as rb_model
from neutron.extensions import agent as ext_agent
from neutron.extensions import l3agentscheduler
from neutron.extensions import router_availability_zone as router_az
from neutron.objects import agent as ag_obj
@ -299,8 +300,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 ext_agent.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

@ -280,6 +280,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: