Merge "cinder list fails with 'name' sort key"

This commit is contained in:
Jenkins 2015-01-23 08:16:42 +00:00 committed by Gerrit Code Review
commit f26de0f8fc
2 changed files with 22 additions and 4 deletions
cinderclient

@ -104,9 +104,24 @@ class ShellTest(utils.TestCase):
self.run_command('list --limit=10')
self.assert_called('GET', '/volumes/detail?limit=10')
def test_list_sort(self):
self.run_command('list --sort_key=name --sort_dir=asc')
self.assert_called('GET', '/volumes/detail?sort_dir=asc&sort_key=name')
def test_list_sort_valid(self):
self.run_command('list --sort_key=id --sort_dir=asc')
self.assert_called('GET', '/volumes/detail?sort_dir=asc&sort_key=id')
def test_list_sort_name(self):
# Client 'name' key is mapped to 'display_name'
self.run_command('list --sort_key=name')
self.assert_called('GET', '/volumes/detail?sort_key=display_name')
def test_list_sort_key_invalid(self):
self.assertRaises(ValueError,
self.run_command,
'list --sort_key=foo --sort_dir=asc')
def test_list_sort_dir_invalid(self):
self.assertRaises(ValueError,
self.run_command,
'list --sort_key=id --sort_dir=foo')
def test_list_reorder_with_sort(self):
# sortby_index is None if there is sort information

@ -24,9 +24,12 @@ except ImportError:
from cinderclient import base
# Valid sort directions and client sort keys
SORT_DIR_VALUES = ('asc', 'desc')
SORT_KEY_VALUES = ('id', 'status', 'size', 'availability_zone', 'name',
'bootable', 'created_at')
# Mapping of client keys to actual sort keys
SORT_KEY_MAPPINGS = {'name': 'display_name'}
class Volume(base.Resource):
@ -260,7 +263,7 @@ class VolumeManager(base.ManagerWithFind):
if sort_key is not None:
if sort_key in SORT_KEY_VALUES:
qparams['sort_key'] = sort_key
qparams['sort_key'] = SORT_KEY_MAPPINGS.get(sort_key, sort_key)
else:
raise ValueError('sort_key must be one of the following: %s.'
% ', '.join(SORT_KEY_VALUES))