Browse Source

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
tags/14.0.0.0b1
wangliangyu 1 year ago
parent
commit
00ecfcdb0b

+ 21
- 0
openstack_dashboard/dashboards/admin/networks/tests.py View File

@@ -936,6 +936,27 @@ class NetworkTests(test.BaseAdminViewTests):
936 936
         networks = res.context['networks_table'].data
937 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 960
     @test.create_stubs({api.neutron: ('is_extension_supported',),
940 961
                         api.keystone: ('tenant_list',)})
941 962
     def test_network_create_without_physical_networks(self):

+ 6
- 0
openstack_dashboard/dashboards/admin/networks/views.py View File

@@ -88,6 +88,12 @@ class IndexView(tables.DataTableView):
88 88
         try:
89 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 97
             # If filter_first is set and if there are not other filters
92 98
             # selected, then search criteria must be provided and return an
93 99
             # empty list

+ 18
- 0
openstack_dashboard/dashboards/admin/routers/tests.py View File

@@ -227,6 +227,24 @@ class RouterTests(test.BaseAdminViewTests, r_test.RouterTests):
227 227
         routers = res.context['table'].data
228 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
 
231 249
 class RouterTestsNoL3Agent(RouterTests):
232 250
     def _get_detail(self, router, extraroute=True):

+ 6
- 0
openstack_dashboard/dashboards/admin/routers/views.py View File

@@ -41,6 +41,12 @@ class IndexView(r_views.IndexView, n_views.IndexView):
41 41
         try:
42 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 50
             # If admin_filter_first is set and if there are not other filters
45 51
             # selected, then search criteria must be provided and return an
46 52
             # empty list

Loading…
Cancel
Save