Bug 1480508 - [Satellite 6.2.10] API call of GET /katello/api/host_collections results in {"displayMessage":"undefined method `id' for nil:NilClass","errors":["undefined method `id' for nil:NilClass"]}
[Satellite 6.2.10] API call of GET /katello/api/host_collections results in ...
Status: VERIFIED
Product: Red Hat Satellite 6
Classification: Red Hat
Component: Host Collections (Show other bugs)
6.2.10
Unspecified Unspecified
unspecified Severity high (vote)
: GA
: --
Assigned To: Anand Agrawal
Nikhil Kathole
: Triaged
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2017-08-11 05:41 EDT by Tapomoy Bhowmik
Modified: 2017-10-09 07:15 EDT (History)
7 users (show)

See Also:
Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed:
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)


External Trackers
Tracker ID Priority Status Summary Last Updated
Foreman Issue Tracker 20574 None None None 2017-08-13 23:08 EDT

  None (edit)
Description Tapomoy Bhowmik 2017-08-11 05:41:36 EDT
Description of problem: `organization_id` parameter is mentioned as optional for `host_collections` API. Without the `organization_id` parameter, API is unable to list all the host collections rather throws below error.

====================
[root@satellite ~]# curl -s -X GET -k -u admin:<password>  'https://<satellite.example.com>/katello/api/v2/host_collections'
{"displayMessage":"undefined method `id' for nil:NilClass","errors":["undefined method `id' for nil:NilClass"]}
[root@satellite ~]# 
====================

The desired output is obtained when the below command is used with `organization_id` parameter.

====================
# curl -s -X GET -k -u admin:<password> 'https://<satellite.example.com>/api/v2/hosts?organization_id=<organization_id>&page=1&paged=true&search=host_collection_id%3D1&sort_by=name&sort_order=ASC'  | json_reformat
====================


Version-Release number of selected component (if applicable): Satellite 6.2.10


How reproducible: Always


Steps to Reproduce:
1. # curl -s -X GET -k -u admin:<password>  'https://<satellite.example.com>/katello/api/v2/host_collections'
2.
3.

Actual results:

====================
[root@satellite ~]# curl -s -X GET -k -u admin:<password>  'https://<satellite.example.com>/katello/api/v2/host_collections'
{"displayMessage":"undefined method `id' for nil:NilClass","errors":["undefined method `id' for nil:NilClass"]}
[root@satellite ~]# 
====================


Expected results: Should list all the host collections.


Additional info:
Comment 2 pm-sat@redhat.com 2017-08-28 22:16:02 EDT
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/20574 has been resolved.
Comment 3 Nikhil Kathole 2017-10-09 07:15:58 EDT
VERIFIED

Version Tested:
Satellite-6.3 Snap 19

steps:

1. curl -s -X GET -k -u admin:<password> 'https://<satellite>/katello/api/v2/host_collection
s'| json_reformat
{
    "total": 3,
    "subtotal": 3,
    "page": 1,
    "per_page": 20,
    "error": null,
    "search": null,
    "sort": {
        "by": "name",
        "order": "asc"
    },
    "results": [
        {
            "name": "host-collection2",
            "organization_id": 1,
            "max_hosts": null,
            "description": null,
            "total_hosts": 0,
            "unlimited_hosts": true,
            "created_at": "2017-10-09 10:58:02 UTC",
            "updated_at": "2017-10-09 10:58:02 UTC",
            "id": 2,
            "permissions": {
                "deletable": true,
                "editable": true
            }
        },
        {
            "name": "host_collection_testing",
            "organization_id": 3,
            "max_hosts": null,
            "description": null,
            "total_hosts": 0,
            "unlimited_hosts": true,
            "created_at": "2017-10-09 11:00:14 UTC",
            "updated_at": "2017-10-09 11:00:14 UTC",
            "id": 3,
            "permissions": {
                "deletable": true,
                "editable": true
            }
        },
        {
            "name": "test_hostcollection",
            "organization_id": 1,
            "max_hosts": null,
            "description": null,
            "total_hosts": 0,
            "unlimited_hosts": true,
            "created_at": "2017-10-09 09:42:16 UTC",
            "updated_at": "2017-10-09 09:42:16 UTC",
            "id": 1,
            "permissions": {
                "deletable": true,
                "editable": true
            }
        }
    ]
}


2. curl -s -X GET -k -u admin:<password> 'https://<satellite>/katello/api/v2/host_collections?organization_id=3'| json_reformat
{
    "total": 1,
    "subtotal": 1,
    "page": 1,
    "per_page": 20,
    "error": null,
    "search": null,
    "sort": {
        "by": "name",
        "order": "asc"
    },
    "results": [
        {
            "name": "host_collection_testing",
            "organization_id": 3,
            "max_hosts": null,
            "description": null,
            "total_hosts": 0,
            "unlimited_hosts": true,
            "created_at": "2017-10-09 11:00:14 UTC",
            "updated_at": "2017-10-09 11:00:14 UTC",
            "id": 3,
            "permissions": {
                "deletable": true,
                "editable": true
            }
        }
    ]

Successfully list all the host collections.

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