Volumes APIs returns a 500 error for an invalid entity body rather than 422

Bug #1048565 reported by Rajalakshmi Ganesan
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Medium
Mark McLoughlin
OpenStack Compute (nova)
Fix Released
Medium
Mark McLoughlin

Bug Description

Description:
------------------

When Request body is sent as "Invalid JSON" request, HTTP 500 ERROR is returned instead of Bad Request exception(code :400).

Environment:
-----------------

Single node Folsom

Consider the following examples
LOG:
----------

1. Server Creation with invalid JSON

rajalakshmi_ganesan@ubuntu:~/latest_source/csbu-qa/AutomatedTests/python_tests/hp_regression/nova/nova_api_tests/volumes$ curl -i http://10.233.52.237:8774/v2/0deffdb2275c478f8689d9f430eca9f4/servers -X POST -H "X-Auth-Project-Id: admin" -H "User-Agent: python-novaclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: ebcf44ed8bcb4a5f90c9af83f6df6fad" -d '{"erver": {"min_count": 1, "flavorRef": "1", "name": "test-3", "imageRef": "bc81d48e-656f-4501-8909-3401121cdf5b", "max_count": 1}}'
HTTP/1.1 500 Internal Server Error
Content-Length: 128
Content-Type: application/json; charset=UTF-8
X-Compute-Request-Id: req-fdde490a-d3d9-4a19-9e48-12d105f996c4
Date: Mon, 10 Sep 2012 15:03:28 GMT

{"computeFault": {"message": "The server has either erred or is incapable of performing the requested operation.", "code": 500}}rajalakshmi_ganesan@ubuntu:~/latest_source/csbu-qa/AutomatedTests/python_tests/hp_regression/nova/nova_api_tests/volumes$

2. Volume Creation with invalid JSON

rajalakshmi_ganesan@ubuntu:~/latest_source/csbu-qa/AutomatedTests/python_tests/hp_regression/nova/nova_api_tests/volumes$ curl -i http://10.233.52.237:8776/v1/0deffdb2275c478f8689d9f430eca9f4/volumes -X POST -H "X-Auth-Project-Id: admin" -H "User-Agent: python-novaclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: 18561d9bc2cf4bd08d4747f3ef0d547c" -d '{"volumeeeeeee": {"display_name": null, "availability_zone": null, "volume_type": null, "display_description": null, "snapshot_id": null, "size": 1}}'
HTTP/1.1 500 Internal Server Error
Content-Length: 128
Content-Type: application/json; charset=UTF-8
X-Compute-Request-Id: req-0f381070-4370-4acf-a49d-ae35737b2e7c
Date: Mon, 10 Sep 2012 15:09:37 GMT

{"computeFault": {"message": "The server has either erred or is incapable of performing the requested operation.", "code": 500}}rajalakshmi_ganesan@ubuntu:~/latest_source/csbu-qa/AutomatedTests/python_tests/hp_regression/nova/nova_api_tests/volumes$

3. Attaching VOLUME to SERVER with invalid JSON

rajalakshmi_ganesan@ubuntu:~/latest_source/csbu-qa/AutomatedTests/python_tests/hp_regression/nova/nova_api_tests/volumes$ curl -i http://10.233.52.237:8774/v2/0deffdb2275c478f8689d9f430eca9f4/servers/fc36fc50-4318-43f2-ac40-c74ee08590f7/os-volume_attachments -X POST -H "X-Auth-Project-Id: admin" -H "User-Agent: python-novaclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: ebcf44ed8bcb4a5f90c9af83f6df6fad" -d '{"volumeattachment": {"device": "/dev/vdz", "volumeId": "6cc71651-d3df-43e0-8d6f-876e7f3cefe2"}}'
HTTP/1.1 500 Internal Server Error
Content-Length: 128
Content-Type: application/json; charset=UTF-8
X-Compute-Request-Id: req-4a5cca99-8e33-49e5-971d-f95f5b65d5c3
Date: Mon, 10 Sep 2012 15:08:35 GMT

{"computeFault": {"message": "The server has either erred or is incapable of performing the requested operation.", "code": 500}}rajalakshmi_ganesan@ubuntu:~/latest_source/csbu-qa/AutomatedTests/python_tests/hp_regression/nova/nova_api_tests/volumes$

Changed in nova:
importance: Undecided → High
status: New → Triaged
milestone: none → folsom-rc1
Thierry Carrez (ttx)
Changed in nova:
importance: High → Medium
Mark McLoughlin (markmc)
Changed in nova:
assignee: nobody → Mark McLoughlin (markmc)
Revision history for this message
Brian Waldon (bcwaldon) wrote :

I'm not able to reproduce this. Can you share the logs of the relevant 500s?

vagrant@precise:~$ curl -d '{"erver": {"min_count": 1, "flavorRef": "1", "name": "test-3", "imageRef": "bc81d48e-656f-4501-8909-3401121cdf5b", "max_count": 1}}' -H 'content-type: application/json' -i -X POST -H 'x-auth-token: 9a344bf6c1f2456bb66595603a0c777f' http://localhost:8774/v2/2dc7470e18614d54a960289c2bafae3b/servers

HTTP/1.1 422 Unprocessable Entity
Content-Length: 90
Content-Type: application/json; charset=UTF-8
X-Compute-Request-Id: req-a10e9102-a54a-462f-aa70-f5331371d706
Date: Tue, 11 Sep 2012 21:43:28 GMT

{"computeFault": {"message": "Unable to process the contained instructions", "code": 422}}

Revision history for this message
Brian Waldon (bcwaldon) wrote :

Are you testing against master (Folsom)?

Revision history for this message
Mark McLoughlin (markmc) wrote :

The servers API issue is similar to bug #1038227 but it shouldn't have been an issue with POST for a long time now

Revision history for this message
Mark McLoughlin (markmc) wrote :

Entity body validation is a pretty general problem we have, so I'm focusing my fixes on the specific areas you raised - the servers example you gave seems to work fine these days, so I've concentrated on the volumes APIs

If you find similar issues in other APIs, please open individual bugs for each of those

Thanks!

summary: - Invalid JSON request is returning 500 ERROR instead of Bad Request 400
- exception
+ Volumes APIs returns a 500 error for an invalid entity body rather than
+ 422
Changed in cinder:
status: New → Confirmed
Changed in nova:
status: Triaged → Confirmed
Changed in cinder:
importance: Undecided → Medium
assignee: nobody → Mark McLoughlin (markmc)
milestone: none → folsom-rc1
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/12865

Changed in nova:
status: Confirmed → In Progress
Changed in cinder:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to cinder (master)

Fix proposed to branch: master
Review: https://review.openstack.org/12867

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (master)

Reviewed: https://review.openstack.org/12867
Committed: http://github.com/openstack/cinder/commit/dcecb586a0578688656d5420c40c26e5a8caa942
Submitter: Jenkins
Branch: master

commit dcecb586a0578688656d5420c40c26e5a8caa942
Author: Mark McLoughlin <email address hidden>
Date: Wed Sep 12 12:51:40 2012 +0100

    Improve entity validation in volumes APIs

    Fixes bug #1048565

    Use the new Controller.is_valid_body() helper to validate the entity
    body in various volumes related POST/PUT handlers and return 422
    as appropriate.

    Change-Id: I04127972981522c1ed81903893396c4f9665bcd3

Changed in cinder:
status: In Progress → Fix Committed
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/12865
Committed: http://github.com/openstack/nova/commit/76ca8c184bed7aa706ac6ef1010c3f4ebf08f7f0
Submitter: Jenkins
Branch: master

commit 76ca8c184bed7aa706ac6ef1010c3f4ebf08f7f0
Author: Mark McLoughlin <email address hidden>
Date: Wed Sep 12 12:51:01 2012 +0100

    Improve entity validation in volumes APIs

    Fixes bug #1048565

    Use the new Controller.is_valid_body() helper to validate the entity
    body in various volumes related POST/PUT handlers and return 422
    as appropriate.

    (Cherry picks commit dcecb586 from Cinder and adds similar fixes for
    the volumes bits in the compute API)

    Change-Id: I04127972981522c1ed81903893396c4f9665bcd3

Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in cinder:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in cinder:
milestone: folsom-rc1 → 2012.2
Thierry Carrez (ttx)
Changed in nova:
milestone: folsom-rc1 → 2012.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.