summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangliangyu <wangliangyu@gohighsec.com>2018-01-23 14:31:12 +0800
committerwangliangyu <wangliangyu@gohighsec.com>2018-02-08 15:27:02 +0800
commit00ecfcdb0b8bcd2de93a80f0929c4d627d5dc04a (patch)
tree0f094062185c164ceb73277f22b9c6875fdce85c
parentddd73b6cbf32fc1a475caa33502ac64a34016baa (diff)
Filtering networks or routers by non-existing tenants return an empty list
When networks or routers are filtered by a tenant which does not exist, there will be return a list no filtered. But we expect an empty list. Change-Id: I8faca01ab67240a76818d6752f796a6de3c51b5f Closes-Bug: #1744846
Notes
Notes (review): Code-Review+2: Akihiro Motoki <amotoki@gmail.com> Code-Review+1: Vladislav Kuzmin <vkuzmin@mirantis.com> Code-Review+1: Allen <chen.qiaomin@99cloud.net> Workflow+1: Akihiro Motoki <amotoki@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 09 Feb 2018 14:50:15 +0000 Reviewed-on: https://review.openstack.org/536687 Project: openstack/horizon Branch: refs/heads/master
-rw-r--r--openstack_dashboard/dashboards/admin/networks/tests.py21
-rw-r--r--openstack_dashboard/dashboards/admin/networks/views.py6
-rw-r--r--openstack_dashboard/dashboards/admin/routers/tests.py18
-rw-r--r--openstack_dashboard/dashboards/admin/routers/views.py6
4 files changed, 51 insertions, 0 deletions
diff --git a/openstack_dashboard/dashboards/admin/networks/tests.py b/openstack_dashboard/dashboards/admin/networks/tests.py
index 4e4aa2d..3f39533 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):
936 networks = res.context['networks_table'].data 936 networks = res.context['networks_table'].data
937 self.assertItemsEqual(networks, []) 937 self.assertItemsEqual(networks, [])
938 938
939 @test.create_stubs({api.keystone: ('tenant_list',),
940 api.neutron: ('is_extension_supported',)})
941 def test_networks_list_with_non_exist_tenant_filter(self):
942 api.neutron.is_extension_supported(
943 IsA(http.HttpRequest),
944 'network_availability_zone').AndReturn(True)
945 api.neutron.is_extension_supported(
946 IsA(http.HttpRequest),
947 'dhcp_agent_scheduler').AndReturn(True)
948 api.keystone.tenant_list(IsA(http.HttpRequest))\
949 .AndReturn([self.tenants.list(), False])
950 self.mox.ReplayAll()
951 self.client.post(
952 reverse('horizon:admin:networks:index'),
953 data={'networks__filter_admin_networks__q_field': 'project',
954 'networks__filter_admin_networks__q': 'non_exist_tenant'})
955 res = self.client.get(reverse('horizon:admin:networks:index'))
956 self.assertTemplateUsed(res, INDEX_TEMPLATE)
957 networks = res.context['networks_table'].data
958 self.assertItemsEqual(networks, [])
959
939 @test.create_stubs({api.neutron: ('is_extension_supported',), 960 @test.create_stubs({api.neutron: ('is_extension_supported',),
940 api.keystone: ('tenant_list',)}) 961 api.keystone: ('tenant_list',)})
941 def test_network_create_without_physical_networks(self): 962 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 15898d8..dbb8131 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):
88 try: 88 try:
89 search_opts = self.get_filters(filters_map=self.FILTERS_MAPPING) 89 search_opts = self.get_filters(filters_map=self.FILTERS_MAPPING)
90 90
91 # If the tenant filter selected and the tenant does not exist.
92 # We do not need to retrieve the list from neutron,just return
93 # an empty list.
94 if 'tenant_id' in search_opts and not search_opts['tenant_id']:
95 return []
96
91 # If filter_first is set and if there are not other filters 97 # If filter_first is set and if there are not other filters
92 # selected, then search criteria must be provided and return an 98 # selected, then search criteria must be provided and return an
93 # empty list 99 # empty list
diff --git a/openstack_dashboard/dashboards/admin/routers/tests.py b/openstack_dashboard/dashboards/admin/routers/tests.py
index 5579669..43a0d30 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):
227 routers = res.context['table'].data 227 routers = res.context['table'].data
228 self.assertItemsEqual(routers, []) 228 self.assertItemsEqual(routers, [])
229 229
230 @test.create_stubs({api.keystone: ('tenant_list',),
231 api.neutron: ('is_extension_supported',)})
232 def test_routers_list_with_non_exist_tenant_filter(self):
233 api.neutron.is_extension_supported(IsA(http.HttpRequest),
234 "router_availability_zone")\
235 .MultipleTimes().AndReturn(True)
236 api.keystone.tenant_list(IsA(http.HttpRequest))\
237 .AndReturn([self.tenants.list(), False])
238 self.mox.ReplayAll()
239 self.client.post(
240 self.INDEX_URL,
241 data={'routers__filter_admin_routers__q_field': 'project',
242 'routers__filter_admin_routers__q': 'non_exist_tenant'})
243 res = self.client.get(self.INDEX_URL)
244 self.assertTemplateUsed(res, INDEX_TEMPLATE)
245 routers = res.context['table'].data
246 self.assertItemsEqual(routers, [])
247
230 248
231class RouterTestsNoL3Agent(RouterTests): 249class RouterTestsNoL3Agent(RouterTests):
232 def _get_detail(self, router, extraroute=True): 250 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 41452a4..c97fdce 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):
41 try: 41 try:
42 filters = self.get_filters(filters_map=self.FILTERS_MAPPING) 42 filters = self.get_filters(filters_map=self.FILTERS_MAPPING)
43 43
44 # If the tenant filter selected and the tenant does not exist.
45 # We do not need to retrieve the list from neutron,just return
46 # an empty list.
47 if 'tenant_id' in filters and not filters['tenant_id']:
48 return []
49
44 # If admin_filter_first is set and if there are not other filters 50 # If admin_filter_first is set and if there are not other filters
45 # selected, then search criteria must be provided and return an 51 # selected, then search criteria must be provided and return an
46 # empty list 52 # empty list