Bug 1552808
| Summary: | API hostgroups/X/hosts listing all hosts instead of hostgroup | ||
|---|---|---|---|
| Product: | Red Hat Satellite | Reporter: | Peter Vreman <peter.vreman> |
| Component: | API | Assignee: | Amit Karsale <akarsale> |
| Status: | CLOSED CURRENTRELEASE | QA Contact: | Katello QA List <katello-qa-list> |
| Severity: | medium | Docs Contact: | |
| Priority: | high | ||
| Version: | 6.3.0 | CC: | akarsale, bbuckingham, jsherril, mhulan, tstrachota |
| Target Milestone: | Unspecified | Keywords: | Triaged |
| Target Release: | Unused | ||
| 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: | 2018-10-18 20:23:38 UTC | Type: | Bug |
| Regression: | --- | Mount Type: | --- |
| Documentation: | --- | CRM: | |
| Verified Versions: | Category: | --- | |
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
| Cloudforms Team: | --- | Target Upstream Version: | |
| Embargoed: | |||
| Bug Depends On: | |||
| Bug Blocks: | 1122832 | ||
It is a generic issue also the environemnts/X/hosts API has the same behaviour
[Unknown Hilti Tier] root@li-lc-1578:~# curl -K /opt/hoici/etc/sat6/curl-hoici.conf "-HContent-Type: application/json" "-d{\"per_page\":9999}" -XGET https://localhost/api/v2/environments/33/hosts | jq . | grep environment_id
"environment_id": 35,
"lifecycle_environment_id": 3,
"environment_id": 27,
"lifecycle_environment_id": 3,
[Unknown Hilti Tier] root@li-lc-1578:~# curl -K /opt/hoici/etc/sat6/curl-hoici.conf "-HContent-Type: application/json" "-d{\"per_page\":9999}" -XGET https://localhost/api/v2/environments/7/hosts | jq . | grep environment_id
"environment_id": 35,
"lifecycle_environment_id": 3,
"environment_id": 27,
"lifecycle_environment_id": 3,
In the sql log output i see queries on the hosts table first with the filter and then directly after it a second query with the filter not included.
---------------
2018-03-07 19:26:48 830a03da [app] [D] Setting current organization thread-local variable to none
2018-03-07 19:26:48 830a03da [sql] [D] Environment Load (0.3ms) SELECT "environments".* FROM "environments" WHERE ("environments"."id" = 33 OR "environments"."name" = '33') ORDER BY environments.name, CASE WHEN "environments"."name" = '33' THEN 1 ELSE 0 END LIMIT 1
2018-03-07 19:26:48 830a03da [sql] [D] Host::Managed Load (0.7ms) SELECT "hosts".* FROM "hosts" INNER JOIN "environments" ON "environments"."id" = "hosts"."environment_id" WHERE "hosts"."type" IN ('Host::Managed') AND ("environments"."id" = 33 OR "environments"."name" = '33') ORDER BY environments.name, CASE WHEN "environments"."name" = '33' THEN 1 ELSE 0 END
2018-03-07 19:26:48 830a03da [sql] [D] Host::Managed Load (0.6ms) SELECT "hosts".* FROM "hosts" INNER JOIN "environments" ON "environments"."id" = "hosts"."environment_id" WHERE "hosts"."type" IN ('Host::Managed')
2018-03-07 19:26:48 830a03da [sql] [D] (0.5ms) SELECT DISTINCT "hosts"."id", "hosts"."name" FROM "hosts" INNER JOIN "environments" ON "environments"."id" = "hosts"."environment_id" WHERE "hosts"."type" IN ('Host::Managed') ORDER BY "hosts"."name" ASC LIMIT 9999 OFFSET 0
2018-03-07 19:26:48 830a03da [app] [I] Rendered api/v2/hosts/thin.json.rabl within api/v2/layouts/index_layout (0.8ms)
2018-03-07 19:26:48 830a03da [sql] [D] CACHE (0.0ms) SELECT "hosts".* FROM "hosts" INNER JOIN "environments" ON "environments"."id" = "hosts"."environment_id" WHERE "hosts"."type" IN ('Host::Managed') AND ("environments"."id" = 33 OR "environments"."name" = '33') ORDER BY environments.name, CASE WHEN "environments"."name" = '33' THEN 1 ELSE 0 END
2018-03-07 19:26:48 830a03da [sql] [D] CACHE (0.0ms) SELECT "hosts".* FROM "hosts" INNER JOIN "environments" ON "environments"."id" = "hosts"."environment_id" WHERE "hosts"."type" IN ('Host::Managed')
2018-03-07 19:26:48 830a03da [sql] [D] (0.5ms) SELECT COUNT(*) FROM "hosts" INNER JOIN "environments" ON "environments"."id" = "hosts"."environment_id" WHERE "hosts"."type" IN ('Host::Managed')
2018-03-07 19:26:48 830a03da [app] [D] Body: {
...
---------------
More analysis showed that the function returns the hosts correctly when there is a hosts assigned
------
[Unknown Hilti Tier] root@li-lc-1578:~# curl -K /opt/hoici/etc/sat6/curl-hoici.conf "-HContent-Type: application/json" "-d{\"per_page\":9999999,\"thin\":true}" -XGET https://localhost:443/api/v2/hostgroups/47/hosts
{
"total": 1,
"subtotal": 1,
"page": 1,
"per_page": 9999999,
"search": null,
"sort": {
"by": null,
"order": null
},
"results": [{"id":2,"name":"li-lc-1442.hag.hilti.com"}]
}
------
That means the problem is that for empty hostgroups (or environments) it will return all hosts instead of empty result.
This is working correct again in Sat6.4Beta
----
[crash/LI] root@li-lc-1578:~# curl -K /opt/hoici/etc/sat6/curl-hoici.conf "-HContent-Type: application/json" "-d{\"per_page\":9999}" -XGET https://localhost/api/v2/hostgroups/66/hosts | jq . | grep hostgroup_id
"hostgroup_id": 66,
[crash/LI] root@li-lc-1578:~# curl -K /opt/hoici/etc/sat6/curl-hoici.conf "-HContent-Type: application/json" "-d{\"per_page\":9999}" -XGET https://localhost/api/v2/hostgroups/1/hosts | jq . | grep hostgroup_id
-----
Thanks Peter! I confirmed the same on a Satellite 6.4 GA instance. i.e. - if the host group has no hosts associated, none are returned - if the host group has hosts associated, they are returned Based upon comment 5, I will go ahead and close this one. If the issue resurfaces, please feel free to re-open. |
Description of problem: The hostgroups/X/hosts filter is not working. As long as X is a valid hostgroup all hosts are returned: [Unknown Hilti Tier] root@li-lc-1578:~# curl -K /opt/hoici/etc/sat6/curl-hoici.conf "-HContent-Type: application/json" "-d{\"per_page\":9999}" -XGET https://localhost/api/v2/hostgroups/66/hosts | jq . | grep hostgroup_id "hostgroup_id": 49, "hostgroup_id": 47, [Unknown Hilti Tier] root@li-lc-1578:~# curl -K /opt/hoici/etc/sat6/curl-hoici.conf "-HContent-Type: application/json" "-d{\"per_page\":9999}" -XGET https://localhost/api/v2/hostgroups/1/hosts | jq . | grep hostgroup_id "hostgroup_id": 49, "hostgroup_id": 47, Version-Release number of selected component (if applicable): How reproducible: Steps to Reproduce: 1. See API call in description 2. 3. Actual results: All hosts returned Expected results: Only Hosts belonging to hostgroup X returned Additional info: