Bug 1116043

Summary: Cannot create an organization.
Product: Red Hat Satellite Reporter: jaudet
Component: APIAssignee: David Davis <daviddavis>
Status: CLOSED CURRENTRELEASE QA Contact: sthirugn <sthirugn>
Severity: medium Docs Contact:
Priority: unspecified    
Version: NightlyCC: bbuckingham, cwelton, daviddavis, ehelms, jaudet, jmontleo, omaciel, sthirugn
Target Milestone: UnspecifiedKeywords: Triaged
Target Release: Unused   
Hardware: Unspecified   
OS: Unspecified   
URL: http://projects.theforeman.org/issues/6786
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-09-11 12:20:16 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:
Attachments:
Description Flags
Screenshot of terminal output when running tests.
none
Log output when creating an org.
none
Lot output when creating an org.
none
Log output when creating an org. none

Description jaudet 2014-07-03 14:37:46 UTC
Created attachment 914489 [details]
Screenshot of terminal output when running tests.

Description of Problem
======================

Cannot create an "Organization" entity.

Version-Release number of selected component (if applicable)
============================================================

* apr-util-ldap-1.3.9-3.el6_0.1.x86_64
* candlepin-0.9.19-1.el6_5.noarch
* candlepin-scl-1-5.el6_4.noarch
* candlepin-scl-quartz-2.1.5-5.el6_4.noarch
* candlepin-scl-rhino-1.7R3-1.el6_4.noarch
* candlepin-scl-runtime-1-5.el6_4.noarch
* candlepin-selinux-0.9.19-1.el6_5.noarch
* candlepin-tomcat6-0.9.19-1.el6_5.noarch
* elasticsearch-0.90.10-4.el6sat.noarch
* foreman-1.6.0.21-1.el6sat.noarch
* foreman-compute-1.6.0.21-1.el6sat.noarch
* foreman-gce-1.6.0.21-1.el6sat.noarch
* foreman-libvirt-1.6.0.21-1.el6sat.noarch
* foreman-ovirt-1.6.0.21-1.el6sat.noarch
* foreman-postgresql-1.6.0.21-1.el6sat.noarch
* foreman-proxy-1.6.0.9-1.el6sat.noarch
* foreman-selinux-1.6.0-5.el6sat.noarch
* foreman-vmware-1.6.0.21-1.el6sat.noarch
* katello-1.5.0-26.el6sat.noarch
* katello-ca-1.0-1.noarch
* katello-certs-tools-1.5.5-1.el6sat.noarch
* katello-installer-0.0.53-1.el6sat.noarch
* openldap-2.4.23-31.el6.x86_64
* pulp-katello-0.3-3.el6sat.noarch
* pulp-nodes-common-2.4.0-0.23.beta.el6sat.noarch
* pulp-nodes-parent-2.4.0-0.23.beta.el6sat.noarch
* pulp-puppet-plugins-2.4.0-0.23.beta.el6sat.noarch
* pulp-puppet-tools-2.4.0-0.23.beta.el6sat.noarch
* pulp-rpm-plugins-2.4.0-0.23.beta.el6sat.noarch
* pulp-selinux-2.4.0-0.23.beta.el6sat.noarch
* pulp-server-2.4.0-0.23.beta.el6sat.noarch
* python-ldap-2.3.10-1.el6.x86_64
* ruby193-rubygem-net-ldap-0.3.1-3.el6sat.noarch
* ruby193-rubygem-runcible-1.1.0-2.el6sat.noarch

How Reproducible
================

100%

Steps to Reproduce
==================

1. Make an HTTP POST request to api/v2/organizations, and only specify a name.
2. Alternately, clone the robottelo source code and execute `nosetests -c robottelo.properties tests/foreman/api/test_organization_v2.py`
3. Alternately, clone the robottelo source code and execute `python -m unittest tests.foreman.api.test_organization_v2`

Actual Results
==============

An HTTP 500 error with the following error message:
"undefined method `[]' for nil:NilClass"

Expected Results
================

Expected an HTTP 201 response status code.

Additional Info
===============

For test source code, see: https://github.com/omaciel/robottelo/blob/master/tests/foreman/api/test_organization_v2.py#L56

There is already a similar test here: https://github.com/omaciel/robottelo/blob/master/tests/foreman/api/test_org.py#L22

However, the existing tests specifies a blank label and description, whereas the failing test completely omits a label and description.

Comment 1 RHEL Program Management 2014-07-03 14:55:29 UTC
Since this issue was entered in Red Hat Bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.

Comment 3 Brad Buckingham 2014-07-08 13:00:37 UTC
If possible, can you attach the server log for the scenario?  (e.g. /var/log/foreman/production.log).

Comment 4 jaudet 2014-07-09 15:30:41 UTC
Created attachment 916857 [details]
Log output when creating an org.

Log output when creating an org and specifying a name of "foo".

Comment 5 jaudet 2014-07-09 15:31:16 UTC
Created attachment 916858 [details]
Lot output when creating an org.

In this case, am creating an org and specifying a name, description and label.

Comment 6 jaudet 2014-07-09 15:32:14 UTC
Created attachment 916860 [details]
Log output when creating an org.

In this case, am creating an org and only specifying a name for that org. The name is a randomly-generated UTF-8 string.

Comment 7 jaudet 2014-07-09 15:32:47 UTC
I've attached three server logs.

1. In the first log, only a name is provided for the organization.
2. In the second log, a name, label and description is provided.
3. In the third log, I let the factory generate random UTF-8 values for the organization name.

In all three cases, I simply copied output from `tail -f /var/log/foreman/production.log`.

Comment 8 jaudet 2014-07-16 00:29:58 UTC
This bug appears to occur only when the request header "content-type" is set to "application/json".

Comment 9 jaudet 2014-07-16 00:30:36 UTC
Ugh. The above should say 'not set to "application/json"'.

Comment 10 jaudet 2014-07-22 18:05:02 UTC
Test code has been written to explicitly target this bug. See here: https://github.com/omaciel/robottelo/blob/master/tests/foreman/api/test_organization_v2.py

Comment 11 Eric Helms 2014-07-25 16:28:29 UTC
Currently there is a workaround that involves using nested params:

Instead of { "name" : "my org" } use { "organization": { "name" : "my org"}}

Comment 12 jaudet 2014-07-25 16:41:12 UTC
To clarify: this bug only occurs when the request header "content-type" is not set to "application/json". In other words:

* If the content-type is set to application/json, you can create an organization.
* If the content-type is set to text/plain, you cannot create an organization.

Comment 13 Bryan Kearney 2014-07-25 18:55:12 UTC
jaudet, does robletto test both content-types?

Comment 14 jaudet 2014-07-25 21:51:21 UTC
Bryan,

Robottelo currently focuses on the application/json content-type. There are very few tests that have a content-type of text/plain. If robottelo was fleshed out with a greater set of tests that used the text/plain content-type, there would be a *lot* more bugs landing in the dev team's queue.

Comment 15 David Davis 2014-07-25 23:24:05 UTC
There's already a Foreman issue open about this (http://projects.theforeman.org/issues/6446). Basically we need to either (1) support non-JSON requests or (2) show a user friendly error.

Comment 16 David Davis 2014-07-25 23:37:50 UTC
I'm happy to tackle the open foreman issue but I'm not sure which solution Foreman  wants to implement. I'll send a message to the foreman-dev list and then try to fix it if there's a consensus.

Comment 17 David Davis 2014-07-26 16:40:14 UTC
Actually, I can fix the nil error in this bug but then you're just going to get a 400 error saying that name can't be blank.

Comment 18 Partha Aji 2014-07-26 16:49:09 UTC
Created redmine issue http://projects.theforeman.org/issues/6786 from this bug

Comment 19 David Davis 2014-07-28 15:57:19 UTC
Bryan, do you mind if I steal this from you?

Comment 20 Bryan Kearney 2014-07-31 14:03:40 UTC
Moving to POST since upstream bug http://projects.theforeman.org/issues/6786 has been closed
-------------
David Davis
I opened a PR to prevent the nil error from being raised. This might suffice as a solution for this bug:

https://github.com/theforeman/foreman/pull/1619

Waiting to here on people's opinions on foreman-dev.
-------------
David Davis
Applied in changeset commit:f5317a04def5c415632190c9c49d95d60f3d83af.

Comment 22 jaudet 2014-08-06 14:10:46 UTC
GitHub pull request #1143 updates the test suite to reflect the changes that have been made. See: https://github.com/omaciel/robottelo/pull/1143

Comment 24 sthirugn@redhat.com 2014-08-13 15:21:20 UTC
Tested three scenarios here:
1. Content-Type: application/json - Success! PASS
curl -X POST -H "Accept:application/json" -H "Content-Type: application/json" -u admin:changeme --insecure -d '{"name":"testorgapi"}' https://host/katello/api/v2/organizations
Success!

2. Content-Type: application/xml - Failed
# curl -X POST -H "Accept:application/xml" -H "Content-Type: application/xml" -u admin:changeme --insecure -d '<name>testorgapi</name>' https://host/katello/api/v2/organizations
{
  "error": {"id":null,"errors":{"name":["can't be blank","can't be blank","cannot be blank"],"title":["can't be blank"],"label":["can't be blank","can't be blank","can't be blank"]},"full_messages":["Name can't be blank","Name can't be blank","Name cannot be blank","Title can't be blank","Label can't be blank","Label can't be blank","Label can't be blank"]}

3. Content-Type: text/plain - Failed
#curl -X POST -H "Accept:application/xml" -H "Content-Type: text/plain" -u admin:changeme --insecure -d 'name=testorgapi' https://host/katello/api/v2/organizations
{
  "error": {"id":null,"errors":{"name":["can't be blank","can't be blank","cannot be blank"],"title":["can't be blank"],"label":["can't be blank","can't be blank","can't be blank"]},"full_messages":["Name can't be blank","Name can't be blank","Name cannot be blank","Title can't be blank","Label can't be blank","Label can't be blank","Label can't be blank"]}

Comment 25 sthirugn@redhat.com 2014-08-13 15:35:48 UTC
Verified as per my Comment 24 above. Created a new issue for unsupported media types issue - https://bugzilla.redhat.com/show_bug.cgi?id=1129769

Version Tested:
GA Snap 4 - Satellite-6.0.4-RHEL-6-20140806.0

* apr-util-ldap-1.3.9-3.el6_0.1.x86_64
* candlepin-0.9.19-1.el6_5.noarch
* candlepin-scl-1-5.el6_4.noarch
* candlepin-scl-quartz-2.1.5-5.el6_4.noarch
* candlepin-scl-rhino-1.7R3-1.el6_4.noarch
* candlepin-scl-runtime-1-5.el6_4.noarch
* candlepin-selinux-0.9.19-1.el6_5.noarch
* candlepin-tomcat6-0.9.19-1.el6_5.noarch
* elasticsearch-0.90.10-4.el6sat.noarch
* foreman-1.6.0.38-1.el6sat.noarch
* foreman-compute-1.6.0.38-1.el6sat.noarch
* foreman-gce-1.6.0.38-1.el6sat.noarch
* foreman-libvirt-1.6.0.38-1.el6sat.noarch
* foreman-ovirt-1.6.0.38-1.el6sat.noarch
* foreman-postgresql-1.6.0.38-1.el6sat.noarch
* foreman-proxy-1.6.0.23-1.el6sat.noarch
* foreman-selinux-1.6.0.4-1.el6sat.noarch
* foreman-vmware-1.6.0.38-1.el6sat.noarch
* katello-1.5.0-28.el6sat.noarch
* katello-ca-1.0-1.noarch
* katello-certs-tools-1.5.6-1.el6sat.noarch
* katello-installer-0.0.57-1.el6sat.noarch
* openldap-2.4.23-34.el6_5.1.x86_64
* pulp-katello-0.3-3.el6sat.noarch
* pulp-nodes-common-2.4.0-0.30.beta.el6sat.noarch
* pulp-nodes-parent-2.4.0-0.30.beta.el6sat.noarch
* pulp-puppet-plugins-2.4.0-0.30.beta.el6sat.noarch
* pulp-puppet-tools-2.4.0-0.30.beta.el6sat.noarch
* pulp-rpm-plugins-2.4.0-0.30.beta.el6sat.noarch
* pulp-selinux-2.4.0-0.30.beta.el6sat.noarch
* pulp-server-2.4.0-0.30.beta.el6sat.noarch
* python-ldap-2.3.10-1.el6.x86_64
* ruby193-rubygem-net-ldap-0.3.1-3.el6sat.noarch
* ruby193-rubygem-runcible-1.1.0-2.el6sat.noarch
* sssd-ldap-1.11.5.1-3.el6.x86_64

Comment 26 Bryan Kearney 2014-09-11 12:20:16 UTC
This was delivered with Satellite 6.0 which was released on 10 September 2014.