Fix sort options --sort-key and --sort-dir in list command.

Previously manila list --sort_key name command sort on
the basis of id instead of name. This PS will fix the
issue and sort the list in terms of name key.

Change-Id: If96162b5269a5a385de9c72c4cef2b335e5c24ff
Closes-Bug: #1777849
Closes-Bug: #1779935
This commit is contained in:
deepak_mourya 2018-06-28 15:05:48 +05:30 committed by Deepak Mourya
parent 8ffe276b60
commit 7b816ceb03
3 changed files with 32 additions and 16 deletions

View File

@ -158,7 +158,11 @@ class ShellTest(test_utils.TestCase):
self.assert_called('GET', '/shares/detail')
cliutils.print_list.assert_called_once_with(
mock.ANY,
['Id', 'Name'])
['Id', 'Name'], sortby_index=None)
def test_list_sort_by_name(self):
self.run_command('list --sort_key name')
self.assert_called('GET', '/shares/detail?sort_key=name')
def test_list_filter_status(self):
for separator in self.separators:
@ -177,7 +181,8 @@ class ShellTest(test_utils.TestCase):
cliutils.print_list.assert_called_once_with(
mock.ANY,
['ID', 'Name', 'Size', 'Share Proto', 'Status', 'Is Public',
'Share Type Name', 'Host', 'Availability Zone', 'Project ID'])
'Share Type Name', 'Host', 'Availability Zone', 'Project ID'],
sortby_index=None)
@mock.patch.object(cliutils, 'print_list', mock.Mock())
def test_list_select_column_and_all_tenants(self):
@ -185,7 +190,7 @@ class ShellTest(test_utils.TestCase):
self.assert_called('GET', '/shares/detail?all_tenants=1')
cliutils.print_list.assert_called_once_with(
mock.ANY,
['Id', 'Name'])
['Id', 'Name'], sortby_index=None)
@mock.patch.object(cliutils, 'print_list', mock.Mock())
def test_list_select_column_and_public(self):
@ -193,7 +198,7 @@ class ShellTest(test_utils.TestCase):
self.assert_called('GET', '/shares/detail?is_public=True')
cliutils.print_list.assert_called_once_with(
mock.ANY,
['Id', 'Name'])
['Id', 'Name'], sortby_index=None)
def test_list_all_tenants_key_and_value_1(self):
for separator in self.separators:
@ -589,7 +594,8 @@ class ShellTest(test_utils.TestCase):
]
self.run_command('list --public')
self.assert_called('GET', '/shares/detail?is_public=True')
cliutils.print_list.assert_called_with(mock.ANY, listed_fields)
cliutils.print_list.assert_called_with(mock.ANY, listed_fields,
sortby_index=None)
def test_show(self):
self.run_command('show 1234')
@ -752,7 +758,7 @@ class ShellTest(test_utils.TestCase):
self.assert_called('GET', '/snapshots/detail')
cliutils.print_list.assert_called_once_with(
mock.ANY,
['Id', 'Name'])
['Id', 'Name'], sortby_index=None)
@mock.patch.object(cliutils, 'print_list', mock.Mock())
def test_list_snapshots_all_tenants_only_key(self):
@ -760,7 +766,8 @@ class ShellTest(test_utils.TestCase):
self.assert_called('GET', '/snapshots/detail?all_tenants=1')
cliutils.print_list.assert_called_once_with(
mock.ANY,
['ID', 'Share ID', 'Status', 'Name', 'Share Size', 'Project ID'])
['ID', 'Share ID', 'Status', 'Name', 'Share Size', 'Project ID'],
sortby_index=None)
def test_list_snapshots_all_tenants_key_and_value_1(self):
for separator in self.separators:
@ -2070,7 +2077,8 @@ class ShellTest(test_utils.TestCase):
self.assert_called('GET', '/share-groups/detail')
cliutils.print_list.assert_called_once_with(
mock.ANY, fields=('ID', 'Name', 'Status', 'Description'))
mock.ANY, fields=('ID', 'Name', 'Status', 'Description'),
sortby_index=None)
@mock.patch.object(cliutils, 'print_list', mock.Mock())
def test_share_group_list_select_column(self):
@ -2078,7 +2086,7 @@ class ShellTest(test_utils.TestCase):
self.assert_called('GET', '/share-groups/detail')
cliutils.print_list.assert_called_once_with(
mock.ANY, fields=['Id', 'Name', 'Description'])
mock.ANY, fields=['Id', 'Name', 'Description'], sortby_index=None)
def test_share_group_list_filter_by_inexact_name(self):
for separator in self.separators:
@ -2268,7 +2276,8 @@ class ShellTest(test_utils.TestCase):
self.assert_called('GET', '/share-group-snapshots/detail')
cliutils.print_list.assert_called_once_with(
mock.ANY, fields=('id', 'name', 'status', 'description'))
mock.ANY, fields=('id', 'name', 'status', 'description'),
sortby_index=None)
@mock.patch.object(cliutils, 'print_list', mock.Mock())
def test_share_group_snapshot_list_select_column(self):
@ -2276,7 +2285,7 @@ class ShellTest(test_utils.TestCase):
self.assert_called('GET', '/share-group-snapshots/detail')
cliutils.print_list.assert_called_once_with(
mock.ANY, fields=['Id', 'Name'])
mock.ANY, fields=['Id', 'Name'], sortby_index=None)
def test_share_group_snapshot_list_all_tenants_only_key(self):
self.run_command('share-group-snapshot-list --all-tenants')

View File

@ -1748,7 +1748,7 @@ def do_list(cs, args):
els = [el.to_dict()['path'] for el in els_objs]
setattr(share, 'export_locations', els)
setattr(share, 'export_location', els[0] if els else None)
cliutils.print_list(shares, list_of_keys)
cliutils.print_list(shares, list_of_keys, sortby_index=None)
if args.count:
print("Shares in total: %s" % total_count)
@ -2049,7 +2049,7 @@ def do_snapshot_list(cs, args):
sort_key=args.sort_key,
sort_dir=args.sort_dir,
)
cliutils.print_list(snapshots, list_of_keys)
cliutils.print_list(snapshots, list_of_keys, sortby_index=None)
@cliutils.arg(
@ -4005,7 +4005,8 @@ def _print_share_group_type_list(share_group_types,
if columns is not None:
fields = _split_columns(columns=columns, title=False)
cliutils.print_list(share_group_types, fields, formatters)
cliutils.print_list(share_group_types, fields, formatters,
sortby_index=None)
def _print_share_group_type(share_group_type, default_share_type=None):
@ -4466,7 +4467,8 @@ def do_share_group_list(cs, args):
share_groups = cs.share_groups.list(
search_opts=search_opts, sort_key=args.sort_key,
sort_dir=args.sort_dir)
cliutils.print_list(share_groups, fields=list_of_keys)
cliutils.print_list(share_groups, fields=list_of_keys,
sortby_index=None)
@cliutils.arg(
@ -4690,7 +4692,8 @@ def do_share_group_snapshot_list(cs, args):
share_group_snapshots = cs.share_group_snapshots.list(
detailed=args.detailed, search_opts=search_opts,
sort_key=args.sort_key, sort_dir=args.sort_dir)
cliutils.print_list(share_group_snapshots, fields=list_of_keys)
cliutils.print_list(share_group_snapshots, fields=list_of_keys,
sortby_index=None)
@cliutils.arg(

View File

@ -0,0 +1,4 @@
---
fixes:
- Fixed bugs 1777849 and 1779935. Name can be used for the sort option
in the list command.