]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
cinder list fails with 'name' sort key
authorKuo-tung Kao <jelly.k@inwinstack.com>
Mon, 6 Jul 2015 06:40:07 +0000 (14:40 +0800)
committerKuo-tung Kao <jelly.k@inwinstack.com>
Mon, 13 Jul 2015 07:56:20 +0000 (15:56 +0800)
Change sort key from `name` to `display_name` if the key, `name` exists.

Change-Id: I9e285c7de2e860b251f881ab82d8d2d93e1191d2
Closes-Bug: #1404020

cinder/api/v2/volumes.py
cinder/tests/unit/api/v2/test_volumes.py

index fd2be7a540d44ea6a48110cbdcb8881b0a5a4690..d6b839bb21683e8498be8aaea7d96d277a3d5ace 100644 (file)
@@ -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']
index eb766afb97d235aa6ede6d0aa441bc118a56930f..a250327674046e39a4d8d2819f055172c031a699 100644 (file)
@@ -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'])