Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1552808 - API hostgroups/X/hosts listing all hosts instead of hostgroup
Summary: API hostgroups/X/hosts listing all hosts instead of hostgroup
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: API
Version: 6.3.0
Hardware: Unspecified
OS: Unspecified
high
medium
Target Milestone: Unspecified
Assignee: Amit Karsale
QA Contact: Katello QA List
URL:
Whiteboard:
Depends On:
Blocks: 1122832
TreeView+ depends on / blocked
 
Reported: 2018-03-07 19:03 UTC by Peter Vreman
Modified: 2021-12-10 15:46 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-10-18 20:23:38 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 24121 0 None None None 2018-07-02 09:03:07 UTC

Description Peter Vreman 2018-03-07 19:03:05 UTC
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:

Comment 1 Peter Vreman 2018-03-07 19:18:14 UTC
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,

Comment 2 Peter Vreman 2018-03-07 19:31:17 UTC
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: {
...
---------------

Comment 3 Peter Vreman 2018-03-08 08:58:24 UTC
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.

Comment 5 Peter Vreman 2018-10-11 11:03:46 UTC
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
-----

Comment 6 Brad Buckingham 2018-10-18 20:23:38 UTC
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.


Note You need to log in before you can comment on or make changes to this bug.