diff --git a/openstack_dashboard/dashboards/admin/networks/tests.py b/openstack_dashboard/dashboards/admin/networks/tests.py index 4e4aa2d2cb..3f395336a0 100644 --- a/openstack_dashboard/dashboards/admin/networks/tests.py +++ b/openstack_dashboard/dashboards/admin/networks/tests.py @@ -936,6 +936,27 @@ class NetworkTests(test.BaseAdminViewTests): networks = res.context['networks_table'].data self.assertItemsEqual(networks, []) + @test.create_stubs({api.keystone: ('tenant_list',), + api.neutron: ('is_extension_supported',)}) + def test_networks_list_with_non_exist_tenant_filter(self): + api.neutron.is_extension_supported( + IsA(http.HttpRequest), + 'network_availability_zone').AndReturn(True) + api.neutron.is_extension_supported( + IsA(http.HttpRequest), + 'dhcp_agent_scheduler').AndReturn(True) + api.keystone.tenant_list(IsA(http.HttpRequest))\ + .AndReturn([self.tenants.list(), False]) + self.mox.ReplayAll() + self.client.post( + reverse('horizon:admin:networks:index'), + data={'networks__filter_admin_networks__q_field': 'project', + 'networks__filter_admin_networks__q': 'non_exist_tenant'}) + res = self.client.get(reverse('horizon:admin:networks:index')) + self.assertTemplateUsed(res, INDEX_TEMPLATE) + networks = res.context['networks_table'].data + self.assertItemsEqual(networks, []) + @test.create_stubs({api.neutron: ('is_extension_supported',), api.keystone: ('tenant_list',)}) def test_network_create_without_physical_networks(self): diff --git a/openstack_dashboard/dashboards/admin/networks/views.py b/openstack_dashboard/dashboards/admin/networks/views.py index 15898d8448..dbb8131a16 100644 --- a/openstack_dashboard/dashboards/admin/networks/views.py +++ b/openstack_dashboard/dashboards/admin/networks/views.py @@ -88,6 +88,12 @@ class IndexView(tables.DataTableView): try: search_opts = self.get_filters(filters_map=self.FILTERS_MAPPING) + # If the tenant filter selected and the tenant does not exist. + # We do not need to retrieve the list from neutron,just return + # an empty list. + if 'tenant_id' in search_opts and not search_opts['tenant_id']: + return [] + # If filter_first is set and if there are not other filters # selected, then search criteria must be provided and return an # empty list diff --git a/openstack_dashboard/dashboards/admin/routers/tests.py b/openstack_dashboard/dashboards/admin/routers/tests.py index 557966985c..43a0d30674 100644 --- a/openstack_dashboard/dashboards/admin/routers/tests.py +++ b/openstack_dashboard/dashboards/admin/routers/tests.py @@ -227,6 +227,24 @@ class RouterTests(test.BaseAdminViewTests, r_test.RouterTests): routers = res.context['table'].data self.assertItemsEqual(routers, []) + @test.create_stubs({api.keystone: ('tenant_list',), + api.neutron: ('is_extension_supported',)}) + def test_routers_list_with_non_exist_tenant_filter(self): + api.neutron.is_extension_supported(IsA(http.HttpRequest), + "router_availability_zone")\ + .MultipleTimes().AndReturn(True) + api.keystone.tenant_list(IsA(http.HttpRequest))\ + .AndReturn([self.tenants.list(), False]) + self.mox.ReplayAll() + self.client.post( + self.INDEX_URL, + data={'routers__filter_admin_routers__q_field': 'project', + 'routers__filter_admin_routers__q': 'non_exist_tenant'}) + res = self.client.get(self.INDEX_URL) + self.assertTemplateUsed(res, INDEX_TEMPLATE) + routers = res.context['table'].data + self.assertItemsEqual(routers, []) + class RouterTestsNoL3Agent(RouterTests): def _get_detail(self, router, extraroute=True): diff --git a/openstack_dashboard/dashboards/admin/routers/views.py b/openstack_dashboard/dashboards/admin/routers/views.py index 41452a4a71..c97fdce053 100644 --- a/openstack_dashboard/dashboards/admin/routers/views.py +++ b/openstack_dashboard/dashboards/admin/routers/views.py @@ -41,6 +41,12 @@ class IndexView(r_views.IndexView, n_views.IndexView): try: filters = self.get_filters(filters_map=self.FILTERS_MAPPING) + # If the tenant filter selected and the tenant does not exist. + # We do not need to retrieve the list from neutron,just return + # an empty list. + if 'tenant_id' in filters and not filters['tenant_id']: + return [] + # If admin_filter_first is set and if there are not other filters # selected, then search criteria must be provided and return an # empty list