Bug 1402799

Summary: Search and filtering don't work well together: empty results
Product: [oVirt] ovirt-engine Reporter: Juan Hernández <juan.hernandez>
Component: RestAPIAssignee: Juan Hernández <juan.hernandez>
Status: CLOSED CURRENTRELEASE QA Contact: Aleksei Slaikovskii <aslaikov>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 4.0.6.1CC: bugs, juan.hernandez, mgoldboi, mperina, oourfali
Target Milestone: ovirt-4.1.0-rcFlags: rule-engine: ovirt-4.0.z+
rule-engine: ovirt-4.1+
mgoldboi: planning_ack+
juan.hernandez: devel_ack+
pstehlik: testing_ack+
Target Release: 4.1.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-02-01 14:53:32 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: Infra RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Juan Hernández 2016-12-08 11:25:59 UTC
The API has the capability to perform searches, using the 'search' query parameter:

  GET /ovirt-engine/api/vms?search=name%3Dmyvm

It also has the capability to filter results according to the permissions of the user, using the 'filter' parameter (or the 'Filter' http header):

  GET /ovirt-engine/api/vms?filter=true

The can be used together as well:

  GET /ovirt-engine/api/vms?search=name%3Dmyvm&filter=true

When doing this, using them together, the implementation performs two separate queries, one for searching and another one for filtering, and then calculates the intersection of the results. But this calculation is computed comparing the objects using the Java Object.equals method. This means that minor differences in the results, like an attribute that isn't populated, will result in excluding that particular result from the intersection. The net result perceived by the user of the API is that the intersection is usually empty. To avoid that we need to calculate the intersection using only the identifiers of the objects.

Comment 1 Sandro Bonazzola 2017-01-25 07:54:17 UTC
4.0.6 has been the last oVirt 4.0 release, please re-target this bug.

Comment 2 Aleksei Slaikovskii 2017-01-30 16:20:01 UTC
Verified on ovirt-engine-4.1.1-0.0.master.

➜  ~ curl -s -k -X GET -u admin@internal:123456 -H "Accept: application/json" https://engine/ovirt-engine/api/vms | grep 123
    "name" : "123",

➜  ~ curl -s -k -X GET -u admin@internal:123456 -H "Accept: application/json" https://engine/ovirt-engine/api/vms\?search\=name\=123 | grep 123
    "name" : "123",

➜  ~ curl -s -k -X GET -u admin@internal:123456 -H "Accept: application/json" https://engine/ovirt-engine/api/vms\?filter\=true | grep 123
    "name" : "123",

➜  ~ curl -s -k -X GET -u admin@internal:123456 -H "Accept: application/json" https://engine/ovirt-engine/api/vms\?search\=name\=123\&filter\=true | grep 123
    "name" : "123",