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.
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.
If possible, can you attach the server log for the scenario? (e.g. /var/log/foreman/production.log).
Created attachment 916857 [details] Log output when creating an org. Log output when creating an org and specifying a name of "foo".
Created attachment 916858 [details] Lot output when creating an org. In this case, am creating an org and specifying a name, description and label.
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.
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`.
This bug appears to occur only when the request header "content-type" is set to "application/json".
Ugh. The above should say 'not set to "application/json"'.
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
Currently there is a workaround that involves using nested params: Instead of { "name" : "my org" } use { "organization": { "name" : "my org"}}
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.
jaudet, does robletto test both content-types?
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.
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.
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.
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.
Created redmine issue http://projects.theforeman.org/issues/6786 from this bug
Bryan, do you mind if I steal this from you?
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.
GitHub pull request #1143 updates the test suite to reflect the changes that have been made. See: https://github.com/omaciel/robottelo/pull/1143
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"]}
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
This was delivered with Satellite 6.0 which was released on 10 September 2014.