Bug 1480508

Summary: [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"]}
Product: Red Hat Satellite Reporter: Tapomoy Bhowmik <tbhowmik>
Component: Host CollectionsAssignee: Anand Agrawal <aagrawal>
Status: CLOSED ERRATA QA Contact: Nikhil Kathole <nkathole>
Severity: high Docs Contact:
Priority: unspecified    
Version: 6.2.10CC: aagrawal, bbuckingham, ehelms, jcallaha, mhulan, nkathole, tstrachota
Target Milestone: UnspecifiedKeywords: 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-02-21 16:54:17 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:

Description Tapomoy Bhowmik 2017-08-11 09:41:36 UTC
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 Satellite Program 2017-08-29 02:16:02 UTC
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 11:15:58 UTC
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.

Comment 4 Satellite Program 2018-02-21 16:54:17 UTC
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA.
> 
> For information on the advisory, and where to find the updated files, follow the link below.
> 
> If the solution does not work for you, open a new bug report.
> 
> https://access.redhat.com/errata/RHSA-2018:0336