cinder list fails with 'name' sort key

Bug #1404020 reported by Steven Kaufer
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Cinder
Fix Released
Undecided
Kuo-tung Kao (jelly)
python-cinderclient
Fix Released
Undecided
Steven Kaufer

Bug Description

The client restricts the sort keys that the user can supply to the following: https://github.com/openstack/python-cinderclient/blob/master/cinderclient/v2/volumes.py#L28-L29

The 'name' is in this list is not correct, it should be 'display_name'.

If 'name' is used then an error occurs:

vagrant@vagrant-ubuntu-trusty-64:/$ cinder list --sort_key name
ERROR: Internal Server Error (HTTP 500) (Request-ID: req-b51cd806-cad1-4f21-8713-8c0474001582)

Steven Kaufer (kaufer)
Changed in python-cinderclient:
assignee: nobody → Steven Kaufer (kaufer)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-cinderclient (master)

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

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

Reviewed: https://review.openstack.org/142964
Committed: https://git.openstack.org/cgit/openstack/python-cinderclient/commit/?id=0560f7883353ea74fd31bf52535883cc18adecf5
Submitter: Jenkins
Branch: master

commit 0560f7883353ea74fd31bf52535883cc18adecf5
Author: Steven Kaufer <email address hidden>
Date: Fri Dec 19 02:56:53 2014 +0000

    cinder list fails with 'name' sort key

    The client restricts the sort keys that the user can supply. The
    'name' key is allowed but is not the correct key for sorting by name,
    it should be 'display_name'.

    If 'name' is used then the client returns with the error 500
    Internal Server Error.

    This patch will add support for mapping client sort keys (eg, 'name')
    to server sort keys (eg, 'display_name'), allowing the user to supply
    the 'name' key to sort by name.

    This patch also adds UT for the sort key and direction error cases
    when an invalid value is supplied.

    Change-Id: I0bdad6d61da83a3924a6b18678afe4722b5778d6
    Closes-Bug: 1404020

Changed in python-cinderclient:
status: In Progress → Fix Committed
Revision history for this message
Eric Harney (eharney) wrote :
Download full text (8.6 KiB)

This seems to be broken in the Cinder API server.

$ cinder list --sort_key name
ERROR: Internal Server Error (HTTP 500) (Request-ID: req-3e740eed-b969-4ee7-a4ca-e27e33686e3c)

paginate_query in cinder/common/sqlalchemyutils.py does:
    sort_key_attr = getattr(model, current_sort_key)

where current_sort_key = 'name'. This returns
    (Pdb) print sort_key_attr
    <property object at 0x42f0730>

since 'name' is a property, whereas other fields return a string that can be used in a query:
    (Pdb) print getattr(model, 'id')
    Volume.id

This generates an invalid sqlalchemy query, which fails as below.

So using 'name' as a sort_key seems to need some additional processing since it is a @property in the sqlalchemy Volume model. The intent may have been for this to map to the display_name field.

2015-03-26 11:17:40.434 DEBUG cinder.volume.api [-] Searching by: MultiDict([('no_migration_targets', True)]). from (pid=20188) get_all /opt/stack/cinder/cinder/volume/api.py:421
2015-03-26 11:17:40.588 ERROR cinder.api.middleware.fault [-] Caught error: SQL expression object or string expected.
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault Traceback (most recent call last):
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault File "/opt/stack/cinder/cinder/api/middleware/fault.py", line 76, in __call__
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault return req.get_response(self.application)
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/request.py", line 1320, in send
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault application, catch_exc_info=False)
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/request.py", line 1284, in call_application
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault app_iter = application(self.environ, start_response)
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/dec.py", line 144, in __call__
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault return resp(environ, start_response)
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/dec.py", line 130, in __call__
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault resp = self.call_func(req, *args, **self.kwargs)
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/dec.py", line 195, in call_func
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault return self.func(req, *args, **kwargs)
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/osprofiler/web.py", line 99, in __call__
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault return request.get_response(self.application)
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault File "/usr/lib/python2.7/site-packages/webob/request.py", line 1320, in send
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fault application, catch_exc_info=False)
2015-03-26 11:17:40.588 TRACE cinder.api.middleware.fau...

Read more...

Changed in cinder:
assignee: nobody → jelly (coding1314)
status: New → Confirmed
Changed in cinder:
status: Confirmed → In Progress
Revision history for this message
Kuo-tung Kao (jelly) (coding1314) wrote :

I send a patch for the cinder bug. https://review.openstack.org/198614

Revision history for this message
Ankit Agrawal (ankitagrawal) wrote :

This issue is not reproducible using cinder list command after above cinderclient patch I0bdad6d61da83a3924a6b18678afe4722b5778d6 is merged. To reproduce this issue in cinder we need to hit following curl command with "name" as a sort key.

$ cinder list --name vol-1
Response: Returns cinder list with a valid response.

$ curl -g -i -X GET http://10.69.4.150:8776/v2/98b3825991904b4db7f277400aa25bef/volumes/detail?sort_key=name -H "User-Agent: python-cinderclient" -H "Accept: application/json" -H "X-Auth-Token: <auth token>"

Response:
HTTP/1.1 500 Internal Server Error
Content-Length: 128
Content-Type: application/json; charset=UTF-8
X-Compute-Request-Id: req-cd271d92-2f83-490e-86ea-9a7049954ef2
X-Openstack-Request-Id: req-cd271d92-2f83-490e-86ea-9a7049954ef2
Date: Mon, 06 Jul 2015 08:38:27 GMT

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

Changed in python-cinderclient:
milestone: none → 1.3.1
status: Fix Committed → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to cinder (master)

Reviewed: https://review.openstack.org/198614
Committed: https://git.openstack.org/cgit/openstack/cinder/commit/?id=3b77f765c065c5f29aef5af2febe086691affebc
Submitter: Jenkins
Branch: master

commit 3b77f765c065c5f29aef5af2febe086691affebc
Author: Kuo-tung Kao <email address hidden>
Date: Mon Jul 6 14:40:07 2015 +0800

    cinder list fails with 'name' sort key

    Change sort key from `name` to `display_name` if the key, `name` exists.

    Change-Id: I9e285c7de2e860b251f881ab82d8d2d93e1191d2
    Closes-Bug: #1404020

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

Duplicates of this bug

Other bug subscribers

Remote bug watches

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