Bug 797971

Summary: [REST API] Domain creation with duplicate name returns 409 with incorrect "messages" section
Product: OKD Reporter: Clayton Coleman <ccoleman>
Component: PodAssignee: John (J5) Palmieri <johnp>
Status: CLOSED CURRENTRELEASE QA Contact: libra bugs <libra-bugs>
Severity: high Docs Contact:
Priority: high    
Version: 2.xCC: bmeng, jkeck, johnp, lnader, mpatel
Target Milestone: ---Keywords: Triaged
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-03-02 21:56:43 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Clayton Coleman 2012-02-27 16:52:47 UTC
Posting a domain name that already exists returns 409, but the "messages" array is not the same structure as other messages and so the site handling fails.  Should be consistent.  Needs to be fixed for sprint exit.

Started POST "/broker/rest/domains.json" for 127.0.0.1 at Mon Feb 27 11:32:12 -0500 2012
  Processing by DomainsController#create as JSON
  Parameters: {"namespace"=>"aoeu"}
Creating domain with namespace aoeu
MongoDataStore.find(CloudUser, test, test)


{\"status\":\"conflict\",\"messages\":[\"A namespace with name 'aoeu' already exists\"],\"version\":\"1.0\",\"data\":null,\"type\":null}"

Comment 1 John (J5) Palmieri 2012-02-28 00:43:05 UTC
I have a fix for this.  Testing it and going to commit it soon.

Comment 2 John (J5) Palmieri 2012-02-28 00:50:58 UTC
committed - issue was we have two code paths for validation errors and exceptions when saving out the namespace.  During namespace saving we now correctly use the Message object to set the error instead of just setting the error message.

I will write unit tests tomorrow and integrate this into the sauce tests I have been working on.

Comment 3 Meng Bo 2012-02-28 09:17:28 UTC
verified on devenv_1648, issue has been fixed.


Output:
<?xml version="1.0" encoding="UTF-8"?>
<response>
  <version>1.0</version>
  <type nil="true"></type>
  <messages>
    <message>
      <field>namespace</field>
      <exit-code>103</exit-code>
      <severity>error</severity>
      <text>A namespace with name 'bmengdev5' already exists</text>
    </message>
  </messages>
  <status>conflict</status>
  <data nil="true"></data>
</response>

Comment 4 Lili Nader 2012-02-28 20:46:40 UTC
I also made changes to domain_controller.rb.  Now it returns

- 409 if the user already has a domain.  Only one domain per user is allowed today.

- 422 if the namespace is already in use.