Filtering for resource tags does not work when calling search_*

Bug #2051698 reported by Simon Hensel
16
This bug affects 2 people
Affects Status Importance Assigned to Milestone
openstacksdk
New
Undecided
Unassigned

Bug Description

While working with the Ansible Openstack.Cloud collection I was trying to figure out why filtering for resource tags is not working. After a little diggin', it turns out that this problem is actually caused by the openstacksdk.

The openstacksdk connection object exposes different methods to search for resource types, which are still used by the Openstack.Cloud collection to retrieve data from the API:
- search_projects
- search_images (btw, this one is not included in the documentation, see https://docs.openstack.org/openstacksdk/latest/user/connection.html and try to find it)
- search_containers
- etc.

When trying to filter for resource tags, these methods always return an empty list, even if the tags are valid. This is caused by the cloud._utils._filter_list method, which seems to do all kinds of things except filtering lists.

One concrete example (code to easily reproduce these steps below):

When calling search_projects(), it calls list_projects():
https://github.com/openstack/openstacksdk/blob/5fef752adbf437138f8bf0ec3467ff3eb2357ec2/openstack/cloud/_identity.py#L131

Which, in turn, calls projects(**query):
https://github.com/openstack/openstacksdk/blob/5fef752adbf437138f8bf0ec3467ff3eb2357ec2/openstack/cloud/_identity.py#L100

Then, search_projects() passes the resulting list (which is already filtered correctly mind you) to the cloud._utils._filter_list() function, which borks the whole thing and returns an empty list: https://github.com/openstack/openstacksdk/blob/5fef752adbf437138f8bf0ec3467ff3eb2357ec2/openstack/cloud/_identity.py#L132

Now, interestingly, search_routers() does NOT call the _utils.filter_list() function and behold! the results are correct:
https://github.com/openstack/openstacksdk/blob/5fef752adbf437138f8bf0ec3467ff3eb2357ec2/openstack/cloud/_network.py#L69

It is also quite telling that the search_* functions are marked as deprecated:
https://github.com/openstack/openstacksdk/blob/5fef752adbf437138f8bf0ec3467ff3eb2357ec2/openstack/cloud/_network.py#L51

Code to reproduce these issue:
Note: When reading the debug log output, we can see that the response body always contains the correct data, so the filtering issue is really on the client side caused by _utils._filter_list

import openstack
openstack.enable_logging(debug=True, http_debug=True)

conn = openstack.connect(cloud="myawesomecloud")

a = conn.identity.projects(**{'tags': 'mytag'}) # working as intended
b = conn.search_projects(filters={'tags': 'mytag'}) # returns an empty list
r = conn.search_routers(filters={'tags': 'mytag'}) # working as intended

print(list(a))
print(b)
print(r)

A few solutions to this problem:
- Remove the use of the _utils._filter_list function and put it in a museum.
- Fix this function so the returned values are correct. Also, while fixing it, please make this code more readable.
- Deprecate and remove the search_* functions altogether.

Bug https://bugs.launchpad.net/openstacksdk/+bug/2043851 is related to this issue.

Once a decision has been made on this topic, I am more that happy to provide patches!

Simon Hensel (shensel)
summary: - Filtering for resource tags does not work
+ Filtering for resource tags does not work when calling search_*
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.