An internal error happens if passing invalid parameter to "create flavor_extraspecs" API

Bug #1264220 reported by Ken'ichi Ohmichi
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Undecided
Ken'ichi Ohmichi

Bug Description

If passing invalid parameter to "create flavor_extraspecs" API, an internal error happens and Traceback is written in log file.
Nova should return BadRequest response instead of internal error.

$ curl -i 'http://10.21.42.109:8774/v2/fd283c7ef47b4f46899403e9ebb1e2ed/flavors/6e05eb08-ef1a-4183-9eb9-5c175060247a/os-extra_specs' [..] -d '{"foo": {"key01": "value01"}}'
HTTP/1.1 500 Internal Server Error
Content-Length: 128
Content-Type: application/json; charset=UTF-8
X-Compute-Request-Id: req-e8b5120c-e585-4095-a387-d3eed52b7415
Date: Thu, 26 Dec 2013 11:06:46 GMT

{"computeFault": {"message": "The server has either erred or is incapable of performing the requested operation.", "code": 500}}
$

** The log of nova-api **
2013-12-26 20:06:46.026 ERROR nova.api.openstack [req-e8b5120c-e585-4095-a387-d3eed52b7415 admin demo] Caught error: 'NoneType' object has no attribute 'keys'
2013-12-26 20:06:46.026 TRACE nova.api.openstack Traceback (most recent call last):
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/opt/stack/nova/nova/api/openstack/__init__.py", line 121, in __call__
2013-12-26 20:06:46.026 TRACE nova.api.openstack return req.get_response(self.application)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/usr/local/lib/python2.7/dist-packages/webob/request.py", line 1296, in send
2013-12-26 20:06:46.026 TRACE nova.api.openstack application, catch_exc_info=False)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/usr/local/lib/python2.7/dist-packages/webob/request.py", line 1260, in call_application
2013-12-26 20:06:46.026 TRACE nova.api.openstack app_iter = application(self.environ, start_response)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 144, in __call__
2013-12-26 20:06:46.026 TRACE nova.api.openstack return resp(environ, start_response)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/opt/stack/python-keystoneclient/keystoneclient/middleware/auth_token.py", line 581, in __call__
2013-12-26 20:06:46.026 TRACE nova.api.openstack return self.app(env, start_response)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 144, in __call__
2013-12-26 20:06:46.026 TRACE nova.api.openstack return resp(environ, start_response)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 144, in __call__
2013-12-26 20:06:46.026 TRACE nova.api.openstack return resp(environ, start_response)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/usr/lib/python2.7/dist-packages/routes/middleware.py", line 131, in __call__
2013-12-26 20:06:46.026 TRACE nova.api.openstack response = self.app(environ, start_response)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 144, in __call__
2013-12-26 20:06:46.026 TRACE nova.api.openstack return resp(environ, start_response)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 130, in __call__
2013-12-26 20:06:46.026 TRACE nova.api.openstack resp = self.call_func(req, *args, **self.kwargs)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/usr/local/lib/python2.7/dist-packages/webob/dec.py", line 195, in call_func
2013-12-26 20:06:46.026 TRACE nova.api.openstack return self.func(req, *args, **kwargs)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/opt/stack/nova/nova/api/openstack/wsgi.py", line 930, in __call__
2013-12-26 20:06:46.026 TRACE nova.api.openstack content_type, body, accept)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/opt/stack/nova/nova/api/openstack/wsgi.py", line 992, in _process_stack
2013-12-26 20:06:46.026 TRACE nova.api.openstack action_result = self.dispatch(meth, request, action_args)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/opt/stack/nova/nova/api/openstack/wsgi.py", line 1073, in dispatch
2013-12-26 20:06:46.026 TRACE nova.api.openstack return method(req=request, **action_args)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/opt/stack/nova/nova/api/openstack/compute/contrib/flavorextraspecs.py", line 76, in create
2013-12-26 20:06:46.026 TRACE nova.api.openstack specs)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/opt/stack/nova/nova/db/api.py", line 1487, in flavor_extra_specs_update_or_create
2013-12-26 20:06:46.026 TRACE nova.api.openstack extra_specs)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/opt/stack/nova/nova/db/sqlalchemy/api.py", line 130, in wrapper
2013-12-26 20:06:46.026 TRACE nova.api.openstack return f(*args, **kwargs)
2013-12-26 20:06:46.026 TRACE nova.api.openstack File "/opt/stack/nova/nova/db/sqlalchemy/api.py", line 4483, in flavor_extra_specs_update_or_create
2013-12-26 20:06:46.026 TRACE nova.api.openstack filter(models.InstanceTypeExtraSpecs.key.in_(specs.keys())).\
2013-12-26 20:06:46.026 TRACE nova.api.openstack AttributeError: 'NoneType' object has no attribute 'keys'

Changed in nova:
assignee: nobody → Ken'ichi Ohmichi (oomichi)
Changed in nova:
status: New → In Progress
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/75721

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

Reviewed: https://review.openstack.org/75721
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=8010c8faf9f030d2c0264189f9e6c70e10a093f2
Submitter: Jenkins
Branch: master

commit 8010c8faf9f030d2c0264189f9e6c70e10a093f2
Author: Ken'ichi Ohmichi <email address hidden>
Date: Mon Feb 24 16:28:41 2014 +0900

    Fix the validation of flavor_extraspecs v2 API

    "create flavor_extraspecs" v2 API does not validate the data type
    of a request body. If invalid parameter is passed, an internal error
    happens. If many invalid requests come, a log file would be occupied
    with traceback.

    In addition, it does not validate the lengths of both key and value of
    extra_specs. extra_specs are stored into the instance_type_extra_specs
    table, and the key and value are defined as String(255).

    This patch fixes the validation code from the viewpoint of data type
    and key/value length.

    Closes-Bug: #1264220

    Change-Id: I195bd5d45a896e9b26dd81dab1e49c9f939b4805

Changed in nova:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in nova:
milestone: none → juno-1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
milestone: juno-1 → 2014.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.