Merge "Do not call list_l3_agent_hosting_router if not supported"

This commit is contained in:
Jenkins 2017-08-03 06:24:01 +00:00 committed by Gerrit Code Review
commit 53dd2dbd39
3 changed files with 30 additions and 10 deletions

View File

@ -198,7 +198,18 @@ class RouterTests(test.BaseAdminViewTests, r_test.RouterTests):
self.assertItemsEqual(routers, [])
class RouterTestsNoL3Agent(RouterTests):
def _get_detail(self, router, extraroute=True):
return super(RouterTests, self)._get_detail(router, extraroute,
lookup_l3=True,
support_l3_agent=False)
class RouterRouteTest(test.BaseAdminViewTests, r_test.RouterRouteTests):
DASHBOARD = 'admin'
INDEX_URL = reverse('horizon:%s:routers:index' % DASHBOARD)
DETAIL_PATH = 'horizon:%s:routers:detail' % DASHBOARD
def _get_detail(self, router, extraroute=True):
return super(RouterRouteTest, self)._get_detail(router, extraroute,
lookup_l3=True)

View File

@ -98,14 +98,18 @@ class DetailView(r_views.DetailView):
context["url"] = self.failure_url
router = context["router"]
# try to lookup the l3 agent location so we know where to troubleshoot
try:
agents = api.neutron.list_l3_agent_hosting_router(self.request,
router.id)
router.l3_host_agents = agents
except Exception:
exceptions.handle(self.request,
_('The L3 agent information could not '
'be located.'))
if api.neutron.is_extension_supported(self.request,
'l3_agent_scheduler'):
try:
agents = api.neutron.list_l3_agent_hosting_router(self.request,
router.id)
router.l3_host_agents = agents
except Exception:
exceptions.handle(self.request,
_('The L3 agent information could not '
'be located.'))
else:
router.l3_host_agents = []
context["actions"] = table.render_row_actions(router)
return context

View File

@ -34,16 +34,21 @@ class RouterMixin(object):
'network_get', 'is_extension_supported',
'list_l3_agent_hosting_router'),
})
def _get_detail(self, router, extraroute=True, lookup_l3=False):
def _get_detail(self, router, extraroute=True, lookup_l3=False,
support_l3_agent=True):
api.neutron.is_extension_supported(IsA(http.HttpRequest), 'extraroute')\
.MultipleTimes().AndReturn(extraroute)
if lookup_l3:
api.neutron.is_extension_supported(IsA(http.HttpRequest),
'l3_agent_scheduler')\
.AndReturn(support_l3_agent)
api.neutron.router_get(IsA(http.HttpRequest), router.id)\
.AndReturn(router)
api.neutron.port_list(IsA(http.HttpRequest),
device_id=router.id)\
.AndReturn([self.ports.first()])
self._mock_external_network_get(router)
if lookup_l3:
if lookup_l3 and support_l3_agent:
agent = self.agents.list()[1]
api.neutron.list_l3_agent_hosting_router(IsA(http.HttpRequest), router.id)\
.AndReturn([agent])