From 47b519106a6a420474b33332415929e17a5e554e Mon Sep 17 00:00:00 2001 From: nidhimittalhada Date: Tue, 6 Oct 2015 16:50:39 +0530 Subject: [PATCH] Manila list shows one export location not multiple "Export Locations" is a plural field. As discussed, "list" operation should not show "export locations" anymore. Hence, removed displaying of it in default mode of list operation. Still, it can be displayed, if specified explicitly, with --columns, wherein a string of comma separated column names can be given. Change-Id: I4ae0cd3760088f1982301aa6f23a5c2d40be2455 Closes-Bug: #1438365 --- manilaclient/tests/functional/client.py | 6 +++++- .../tests/functional/test_shares_listing.py | 6 ++++++ manilaclient/tests/unit/v1/test_shell.py | 3 +-- manilaclient/v1/shell.py | 16 ++++++++++++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/manilaclient/tests/functional/client.py b/manilaclient/tests/functional/client.py index 607f9b383..937b3c31e 100644 --- a/manilaclient/tests/functional/client.py +++ b/manilaclient/tests/functional/client.py @@ -509,7 +509,7 @@ class ManilaCLIClient(base.CLIClient): cmd += '%s ' % share return self.manila(cmd) - def list_shares(self, all_tenants=False, filters=None): + def list_shares(self, all_tenants=False, filters=None, columns=None): """List shares. :param all_tenants: bool -- whether to list shares that belong @@ -521,6 +521,8 @@ class ManilaCLIClient(base.CLIClient): {--'project_id': 'foo'} {'project-id': 'foo'} will be transformed to filter parameter "--project-id=foo" + :param columns: comma separated string of columns. + Example, "--columns Name,Size" """ cmd = 'list ' if all_tenants: @@ -529,6 +531,8 @@ class ManilaCLIClient(base.CLIClient): for k, v in filters.items(): cmd += '%(k)s=%(v)s ' % { 'k': self._stranslate_to_cli_optional_param(k), 'v': v} + if columns is not None: + cmd += '--columns ' + columns shares_raw = self.manila(cmd) shares = utils.listing(shares_raw) return shares diff --git a/manilaclient/tests/functional/test_shares_listing.py b/manilaclient/tests/functional/test_shares_listing.py index a20e9a9f3..260e8e29d 100644 --- a/manilaclient/tests/functional/test_shares_listing.py +++ b/manilaclient/tests/functional/test_shares_listing.py @@ -204,3 +204,9 @@ class SharesListReadWriteTest(base.BaseTestCase): def test_list_shares_with_limit(self, filters): shares = self.user_client.list_shares(filters=filters) self.assertEqual(filters['limit'], len(shares)) + + def test_list_share_select_column(self): + shares = self.user_client.list_shares(columns="Name,Size") + self.assertTrue(any(s['Name'] is not None for s in shares)) + self.assertTrue(any(s['Size'] is not None for s in shares)) + self.assertTrue(all('Description' not in s for s in shares)) diff --git a/manilaclient/tests/unit/v1/test_shell.py b/manilaclient/tests/unit/v1/test_shell.py index 9091a447e..127060b98 100644 --- a/manilaclient/tests/unit/v1/test_shell.py +++ b/manilaclient/tests/unit/v1/test_shell.py @@ -458,8 +458,7 @@ class ShellTest(test_utils.TestCase): 'Share Proto', 'Status', 'Is Public', - 'Share Type', - 'Export location', + 'Share Type Name', 'Host', 'Availability Zone' ] diff --git a/manilaclient/v1/shell.py b/manilaclient/v1/shell.py index 59d4c60e4..cd0d3b15d 100644 --- a/manilaclient/v1/shell.py +++ b/manilaclient/v1/shell.py @@ -925,15 +925,27 @@ def do_access_list(cs, args): default=None, action='single_alias', help='Filter results by consistency group name or ID.') +@cliutils.arg( + '--columns', + metavar='', + type=str, + default=None, + help='Comma separated list of columns to be displayed ' + 'e.g. --columns "export_location,is public"') @cliutils.service_type('sharev2') def do_list(cs, args): """List NAS shares with filters.""" + list_of_keys = [ 'ID', 'Name', 'Size', 'Share Proto', 'Status', 'Is Public', - 'Share Type', 'Export location', 'Host', 'Availability Zone' + 'Share Type Name', 'Host', 'Availability Zone' ] - all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) + columns = args.columns + if columns is not None: + list_of_keys = map(lambda x: x.strip().title(), columns.split(",")) + + all_tenants = int(os.environ.get("ALL_TENANTS", args.all_tenants)) empty_obj = type('Empty', (object,), {'id': None}) share_type = (_find_share_type(cs, args.share_type) if args.share_type else empty_obj)