Bläddra i källkod

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 2 år sedan
förälder
incheckning
00ecfcdb0b
4 ändrade filer med 51 tillägg och 0 borttagningar
  1. +21
    -0
      openstack_dashboard/dashboards/admin/networks/tests.py
  2. +6
    -0
      openstack_dashboard/dashboards/admin/networks/views.py
  3. +18
    -0
      openstack_dashboard/dashboards/admin/routers/tests.py
  4. +6
    -0
      openstack_dashboard/dashboards/admin/routers/views.py

+ 21
- 0
openstack_dashboard/dashboards/admin/networks/tests.py Visa fil

@@ -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):


+ 6
- 0
openstack_dashboard/dashboards/admin/networks/views.py Visa fil

@@ -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


+ 18
- 0
openstack_dashboard/dashboards/admin/routers/tests.py Visa fil

@@ -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):


+ 6
- 0
openstack_dashboard/dashboards/admin/routers/views.py Visa fil

@@ -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


Laddar…
Avbryt
Spara