From 9e6ddb7a0a53173f62566d5e829ff3ea4527937c Mon Sep 17 00:00:00 2001 From: vinay_m Date: Mon, 28 Sep 2020 14:22:18 +0530 Subject: Non-api filters not working with admin instance tab The issue was that the filtering opts like project_name, image_name, flavor_name that are not supported by nova API (non-api filters) do not work expectedly. These filters are mapped to their IDs [1], but an instance list retrieved before resolving non-API filters is used [2]. This commit changes the logic to resolve non-API filters first and then retrieve instances using the updated search_opts. Note that the image list is handled a bit specially. If 'image_name' is specified as a filter, we retrieve a corresponding image detail first before fetching instances to resolve the image name into its ID. Otherwise, we retrieve images only related to instances retrieved and this happens after retrieving instances. [1] https://opendev.org/openstack/horizon/src/commit/f90c3cd50174af4927737e29e2765cd2d7ca507f/openstack_dashboard/dashboards/admin/instances/views.py#L166 [2] https://opendev.org/openstack/horizon/src/commit/f90c3cd50174af4927737e29e2765cd2d7ca507f/openstack_dashboard/dashboards/admin/instances/views.py#L154 Closes-Bug: #1888490 Co-Authored-By: Akihiro Motoki Change-Id: Id43adbd44778d3375c0d49da3f7530cbb99e16fe (cherry picked from commit 6b79cdcc1b92a968c967286cc267bac39803c85e) --- .../dashboards/admin/instances/views.py | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/openstack_dashboard/dashboards/admin/instances/views.py b/openstack_dashboard/dashboards/admin/instances/views.py index 8ca198772..d8a6e2cb8 100644 --- a/openstack_dashboard/dashboards/admin/instances/views.py +++ b/openstack_dashboard/dashboards/admin/instances/views.py @@ -108,6 +108,12 @@ class AdminIndexView(tables.PagedTableMixin, tables.DataTableView): exceptions.handle(self.request, ignore=True) return {} + def _get_images_by_name(self, image_name): + result = api.glance.image_list_detailed( + self.request, filters={'name': image_name}) + images = result[0] + return dict((image.id, image) for image in images) + def _get_flavors(self): # Gather our flavors to correlate against IDs try: @@ -151,22 +157,32 @@ class AdminIndexView(tables.PagedTableMixin, tables.DataTableView): self._needs_filter_first = False - instances = self._get_instances(search_opts, sort_dir) results = futurist_utils.call_functions_parallel( - (self._get_images, [tuple(instances)]), self._get_flavors, self._get_tenants) - image_dict, flavor_dict, tenant_dict = results + flavor_dict, tenant_dict = results - non_api_filter_info = ( + non_api_filter_info = [ ('project', 'tenant_id', tenant_dict.values()), - ('image_name', 'image', image_dict.values()), ('flavor_name', 'flavor', flavor_dict.values()), - ) + ] + + filter_by_image_name = 'image_name' in search_opts + if filter_by_image_name: + image_dict = self._get_images_by_name(search_opts['image_name']) + non_api_filter_info.append( + ('image_name', 'image', image_dict.values()) + ) + if not views.process_non_api_filters(search_opts, non_api_filter_info): self._more = False return [] + instances = self._get_instances(search_opts, sort_dir) + + if not filter_by_image_name: + image_dict = self._get_images(tuple(instances)) + # Loop through instances to get image, flavor and tenant info. for inst in instances: if hasattr(inst, 'image') and isinstance(inst.image, dict): -- cgit v1.2.1