ValueError causes 500 to return to client

Bug #1392409 reported by Srinivas Sakhamuri
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ceilometer
Invalid
Undecided
Unassigned
WSME
Fix Released
Undecided
Stéphane Bisinger

Bug Description

At present the input json validation in WSME causes a 500 to be thrown to the client. It should ideally throw a 400 - input error in case of validation failures. Here is the relevant stack trace. This is from ceilometer API when invoked with the following command

ceilometer -vd sample-create -r 123 -m storage.objects --meter-type gauge --meter-unit object --sample-volume 10 --timestamp 1415702780

2014-11-13 17:05:51.215 8166 ERROR wsme.api [-] Server-side error: "year is out of range". Detail:
Traceback (most recent call last):

  File "/usr/local/lib/python2.7/dist-packages/wsmeext/pecan.py", line 80, in callfunction
    pecan.request.body, pecan.request.content_type

  File "/usr/local/lib/python2.7/dist-packages/wsme/rest/args.py", line 284, in get_args
    from_body = args_from_body(funcdef, body, mimetype)

  File "/usr/local/lib/python2.7/dist-packages/wsme/rest/args.py", line 230, in args_from_body
    body, datatypes, bodyarg=funcdef.body_type is not None

  File "/usr/local/lib/python2.7/dist-packages/wsme/rest/json.py", line 224, in parse
    kw = {argname: fromjson(datatypes[argname], jdata)}

  File "/usr/local/lib/python2.7/dist-packages/simplegeneric.py", line 63, in dispatch
    return f(*args, **kw)

  File "/usr/local/lib/python2.7/dist-packages/wsme/rest/json.py", line 157, in array_fromjson
    return [fromjson(datatype.item_type, item) for item in value]

  File "/usr/local/lib/python2.7/dist-packages/simplegeneric.py", line 63, in dispatch
    return f(*args, **kw)

  File "/usr/local/lib/python2.7/dist-packages/wsme/rest/json.py", line 138, in fromjson
    val_fromjson = fromjson(attrdef.datatype, value[attrdef.name])

  File "/usr/local/lib/python2.7/dist-packages/simplegeneric.py", line 67, in dispatch
    return f[1](*args, **kw)

  File "/usr/local/lib/python2.7/dist-packages/wsme/rest/json.py", line 212, in datetime_fromjson
    return wsme.utils.parse_isodatetime(value)

  File "/usr/local/lib/python2.7/dist-packages/wsme/utils.py", line 65, in parse_isodatetime
    return dateutil.parser.parse(value)

  File "/usr/lib/python2.7/dist-packages/dateutil/parser.py", line 697, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)

  File "/usr/lib/python2.7/dist-packages/dateutil/parser.py", line 310, in parse
    ret = default.replace(**repl)

ValueError: year is out of range

10.0.0.15 - - [13/Nov/2014 17:05:51] "POST /v2/meters/storage.objects HTTP/1.1" 500 100

Changed in wsme:
assignee: nobody → Stéphane Bisinger (kjir)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to wsme (master)

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

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

Reviewed: https://review.openstack.org/177026
Committed: https://git.openstack.org/cgit/stackforge/wsme/commit/?id=f66cf4c3cc1323ec563bdb22d26fb5c6b585b32f
Submitter: Jenkins
Branch: master

commit f66cf4c3cc1323ec563bdb22d26fb5c6b585b32f
Author: Stéphane Bisinger <email address hidden>
Date: Fri Apr 24 00:55:09 2015 +0200

    Raise an InvalidInput if you get a ValueError from JSON data.

    When you parse JSON, if some parts of the message have the wrong type of data
    you would get a ValueError, returning a 500 HTTP status code. Now the
    ValueError gets wrapped in an InvalidInput which will result in a 400 HTTP
    response sent back to the client.

    Closes-Bug: #1392409
    Change-Id: I7702b824a98185d194a29d593b23e47dfd9bca3e

Changed in wsme:
status: In Progress → Fix Committed
Mehdi Abaakouk (sileht)
Changed in ceilometer:
status: New → Invalid
Changed in wsme:
milestone: none → 0.8.0
status: Fix Committed → Fix Released
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.