diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-02-23 22:04:17 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-02-23 22:04:17 +0000 |
commit | 13a29b5a3263ae7c4249b3425c8ea3bf9801e578 (patch) | |
tree | 93b9e33d4964ee3f700da42bbd3a570bd1a55b17 | |
parent | 79750ab8ad1482ffc52e89b908a645f4c33d843a (diff) | |
parent | c18f9073a48649a05cc3c389101aa0f94a121f0f (diff) | |
download | python-cinderclient-13a29b5a3263ae7c4249b3425c8ea3bf9801e578.tar.gz |
Merge "Fix sort problem in snapshot and backup list"
-rw-r--r-- | cinderclient/tests/unit/v2/test_shell.py | 17 | ||||
-rw-r--r-- | cinderclient/v2/shell.py | 14 |
2 files changed, 29 insertions, 2 deletions
diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 03f25f6..2f5436f 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -467,6 +467,14 @@ class ShellTest(utils.TestCase): self.assert_called('GET', '/snapshots/detail?' 'status=available&volume_id=1234') + @mock.patch("cinderclient.utils.print_list") + def test_snapshot_list_sort(self, mock_print_list): + self.run_command('snapshot-list --sort id') + self.assert_called('GET', '/snapshots/detail?sort=id') + columns = ['ID', 'Volume ID', 'Status', 'Name', 'Size'] + mock_print_list.assert_called_once_with(mock.ANY, columns, + sortby_index=None) + def test_rename(self): # basic rename with positional arguments self.run_command('rename 1234 new-name') @@ -1180,6 +1188,15 @@ class ShellTest(utils.TestCase): self.run_command('backup-list') self.assert_called('GET', '/backups/detail') + @mock.patch("cinderclient.utils.print_list") + def test_backup_list_sort(self, mock_print_list): + self.run_command('backup-list --sort id') + self.assert_called('GET', '/backups/detail?sort=id') + columns = ['ID', 'Volume ID', 'Status', 'Name', 'Size', 'Object Count', + 'Container'] + mock_print_list.assert_called_once_with(mock.ANY, columns, + sortby_index=None) + def test_get_capabilities(self): self.run_command('get-capabilities host') self.assert_called('GET', '/capabilities/host') diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py index b7b01d4..143d199 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -684,8 +684,14 @@ def do_snapshot_list(cs, args): limit=args.limit, sort=args.sort) _translate_volume_snapshot_keys(snapshots) + if args.sort: + sortby_index = None + else: + sortby_index = 0 + utils.print_list(snapshots, - ['ID', 'Volume ID', 'Status', 'Name', 'Size']) + ['ID', 'Volume ID', 'Status', 'Name', 'Size'], + sortby_index=sortby_index) @utils.arg('snapshot', @@ -1469,7 +1475,11 @@ def do_backup_list(cs, args): _translate_volume_snapshot_keys(backups) columns = ['ID', 'Volume ID', 'Status', 'Name', 'Size', 'Object Count', 'Container'] - utils.print_list(backups, columns) + if args.sort: + sortby_index = None + else: + sortby_index = 0 + utils.print_list(backups, columns, sortby_index=sortby_index) @utils.arg('backup', metavar='<backup>', nargs='+', |