From: Kuo-tung Kao Date: Mon, 6 Jul 2015 06:40:07 +0000 (+0800) Subject: cinder list fails with 'name' sort key X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3b77f765c065c5f29aef5af2febe086691affebc;p=openstack-build%2Fcinder-build.git 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 --- diff --git a/cinder/api/v2/volumes.py b/cinder/api/v2/volumes.py index fd2be7a54..d6b839bb2 100644 --- a/cinder/api/v2/volumes.py +++ b/cinder/api/v2/volumes.py @@ -238,6 +238,9 @@ class VolumeController(wsgi.Controller): self._get_volume_filter_options()) # NOTE(thingee): v2 API allows name instead of display_name + if 'name' in sort_keys: + sort_keys[sort_keys.index('name')] = 'display_name' + if 'name' in filters: filters['display_name'] = filters['name'] del filters['name'] diff --git a/cinder/tests/unit/api/v2/test_volumes.py b/cinder/tests/unit/api/v2/test_volumes.py index eb766afb9..a25032767 100644 --- a/cinder/tests/unit/api/v2/test_volumes.py +++ b/cinder/tests/unit/api/v2/test_volumes.py @@ -1619,6 +1619,21 @@ class VolumeApiTest(test.TestCase): sort_keys=['created_at'], sort_dirs=['desc'], filters={'availability_zone': 'nova'}, viewable_admin_meta=True) + @mock.patch('cinder.volume.api.API.get_all') + def test_get_volumes_sort_by_name(self, get_all): + """Name in client means display_name in database.""" + + req = mock.MagicMock() + ctxt = context.RequestContext('fake', 'fake', auth_token=True) + req.environ = {'cinder.context': ctxt} + req.params = {'sort': 'name'} + self.controller._view_builder.detail_list = mock.Mock() + self.controller._get_volumes(req, True) + get_all.assert_called_once_with( + ctxt, None, None, + sort_dirs=['desc'], viewable_admin_meta=True, + sort_keys=['display_name'], filters={}) + def test_get_volume_filter_options_using_config(self): self.override_config('query_volume_filters', ['name', 'status', 'metadata'])