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

This commit is contained in:
Zuul 2018-08-16 21:39:19 +00:00 committed by Gerrit Code Review
commit 4132b2186a
3 changed files with 32 additions and 16 deletions

View File

@ -159,7 +159,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:
@ -178,7 +182,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):
@ -186,7 +191,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):
@ -194,7 +199,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:
@ -602,7 +607,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')
@ -765,7 +771,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):
@ -773,7 +779,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:
@ -2128,7 +2135,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):
@ -2136,7 +2144,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:
@ -2326,7 +2334,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):
@ -2334,7 +2343,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

@ -1828,7 +1828,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)
@ -2129,7 +2129,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(
@ -4099,7 +4099,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):
@ -4561,7 +4562,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(
@ -4785,7 +4787,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.