From 3b77f765c065c5f29aef5af2febe086691affebc Mon Sep 17 00:00:00 2001 From: Kuo-tung Kao Date: Mon, 6 Jul 2015 14:40:07 +0800 Subject: [PATCH] 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 --- cinder/api/v2/volumes.py | 3 +++ cinder/tests/unit/api/v2/test_volumes.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) 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']) -- 2.45.2