Bug 1120800 - Can't create a host via the API because params aren't correctly wrapped
Summary: Can't create a host via the API because params aren't correctly wrapped
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Satellite 6
Classification: Red Hat
Component: Provisioning
Version: 6.0.4
Hardware: Unspecified
OS: Unspecified
unspecified
high vote
Target Milestone: Unspecified
Assignee: jmagen@redhat.com
QA Contact: Katello QA List
URL: http://projects.theforeman.org/issues...
Whiteboard:
Depends On: 1135651
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-07-17 18:03 UTC by Tom McKay
Modified: 2017-02-23 21:12 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-05-04 13:44:33 UTC


Attachments (Terms of Use)


Links
System ID Priority Status Summary Last Updated
Foreman Issue Tracker 6696 None None None 2016-04-22 16:35:31 UTC

Description Tom McKay 2014-07-17 18:03:37 UTC
When I try the following curl command, I get "Name can't be blank":

<pre>
$ curl -k -u admin:changeme -H "Content-Type: application/json" -X POST http://localhost:3000/api/v2/hosts -d '{"name": "TEST"}'
</pre>

It looks like the name param is getting wrapped in params[:base] instead of params[:host].

Comment 1 Tom McKay 2014-07-17 18:03:38 UTC
Created from redmine issue http://projects.theforeman.org/issues/6674

Comment 3 Bryan Kearney 2014-07-18 12:04:09 UTC
Upstream bug assigned to tomckay@redhat.com

Comment 4 Bryan Kearney 2014-07-28 20:29:23 UTC
Connecting redmine issue http://projects.theforeman.org/issues/6696 from this bug

Comment 5 Bryan Kearney 2014-08-11 10:03:46 UTC
Moving to POST since upstream bug http://projects.theforeman.org/issues/6696 has been closed
-------------
Joseph Magen
Applied in changeset commit:a2610e980c66663db2a200cedceb2a0b53918f3a.

Comment 8 sthirugn@redhat.com 2014-08-29 22:23:33 UTC
Currently failed because of https://bugzilla.redhat.com/show_bug.cgi?id=1135651.

Comment 9 sthirugn@redhat.com 2014-08-29 22:26:15 UTC
Failed based on Comment 8

Comment 10 jmagen@redhat.com 2014-09-03 08:15:01 UTC
Comment 8 refers to https://bugzilla.redhat.com/show_bug.cgi?id=1135651 which is fixed by https://github.com/theforeman/foreman/pull/1732

However, fix to this bug was already merged with commit a2610e980c66663db2a200cedceb2a0b53918f3a

Comment 11 jmagen@redhat.com 2014-09-03 09:19:02 UTC
PR #1732 reached an impasse. The parameters are technically required on all situations. It depends on various scenarios. See also http://projects.theforeman.org/issues/6997

Comment 14 jaudet 2015-03-11 19:51:26 UTC
POSTing to `api/v2/host` with this JSON payload:

    {
        u'host': {
            'architecture_id': 73,
            'domain_id': 67,
            'environment_id': 105,
            'location_id': 341,
            'mac': u'12:16:49:91:72:21',
            'medium_id': 68,
            'operatingsystem_id': 67,
            'organization_id': 342,
            'ptable_id': 64,
            'root_pass': u'…',
        },
        'name': u'dPRwSiClzbUNZeLLApBC',
    }

Results in this JSON response:

    {
        u'error': {
            u'errors': {u'name': [u"can't be blank", u'is invalid']},
            u'id': None,
            u'full_messages': [u"Name can't be blank", u'Name is invalid']
        }
    }

Moving the "name" parameter into the inner hash succeeds:

    {
        u'host': {
            'architecture_id': 73,
            'domain_id': 67,
            'environment_id': 105,
            'location_id': 341,
            'mac': u'12:16:49:91:72:21',
            'medium_id': 68,
            'name': u'dPRwSiClzbUNZeLLApBC',
            'operatingsystem_id': 67,
            'organization_id': 342,
            'ptable_id': 64,
            'root_pass': u'…',
        }
    }

This bug has not been fixed. Placing "name" in the outer hash still prevents
API users from creating hosts. However, it's worth noting that the API doc
specifically shows that the "name" parameter should be in the inner hash in the
first place, along with all other parameters:

> host[name]
> required
> Value: String 

If you do try to create a host by plaing all parameters in an outer hash,
you'll receive this response:

    {
        u'error': {
            u'message': u'operatingsystem_id is not allowed as nested parameter
            for hosts. Allowed parameters are hostgroup_id, location_id,
            organization_id, environment_id'
        }
    }

I do not think that this bug is valid. It is possible to create a host via the
API, and this bug describes an action which is not listed as being possible.

Comment 15 jaudet 2015-03-11 19:54:19 UTC
Ah, I forgot to mention that this bug was tested against systems running:

* Satellite-6.1.0-RHEL-6-20150310.0
* Satellite-6.1.0-RHEL-7-20150310.0

Comment 16 jaudet 2015-03-11 19:59:05 UTC
Automated tests should be added to QE's test suite shortly. See: https://github.com/SatelliteQE/robottelo/pull/1978

Comment 17 Bryan Kearney 2015-05-04 13:44:33 UTC
Per #c14, I am closing this out. Discussions wit Jmagen agree.


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