diff options
author | LisaLi <xiaoyan.li@intel.com> | 2016-01-20 16:54:39 +0800 |
---|---|---|
committer | LisaLi <xiaoyan.li@intel.com> | 2016-01-20 08:53:38 +0000 |
commit | c18f9073a48649a05cc3c389101aa0f94a121f0f (patch) | |
tree | b7064ed63f3e0e496fa4b1ea008dc3b460157af0 | |
parent | aa06b2dd5442704548a2372cffc56a24de98882d (diff) | |
download | python-cinderclient-c18f9073a48649a05cc3c389101aa0f94a121f0f.tar.gz |
Fix sort problem in snapshot and backup list
The sort in command snapshot-list and backup-list
doesn't work, and they show same results.
The patch is to fix the problem, and transfer
sortby_index as None in utils.print_list.
Closes-Bug: #1536054
Change-Id: I00760fd4b395b04b95a8139224e18ea8d649d377
-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 fa36f10..b6b23e7 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -450,6 +450,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') @@ -1163,6 +1171,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 6b3a4f2..a501edf 100644 --- a/cinderclient/v2/shell.py +++ b/cinderclient/v2/shell.py @@ -677,8 +677,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', @@ -1457,7 +1463,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>', |