Fix using column reports nothing for capabilities

1. Fix manila pool-list --column reports nothing for
   capabilities
2. Format the result of manila pool-list --detail

Change-Id: I09bab5a3eaa28e6773afdfc2ac0b99295d725cc1
Closes-bug: #1717940
This commit is contained in:
junboli 2018-07-17 10:00:21 +08:00
parent 270266b791
commit a94c76df1c
4 changed files with 22 additions and 10 deletions

View File

@ -1154,7 +1154,7 @@ class ManilaCLIClient(base.CLIClient):
def pool_list(self, detail=False):
cmd = 'pool-list'
if detail:
cmd += ' --detail'
cmd += ' --column name,host,backend,pool,capabilities'
response = self.manila(cmd)
return output_parser.listing(response)

View File

@ -2000,23 +2000,22 @@ class ShellTest(test_utils.TestCase):
def test_quota_update_with_wrong_combinations(self, cmd):
self.assertRaises(exceptions.CommandError, self.run_command, cmd)
@mock.patch.object(cliutils, 'print_list', mock.Mock())
@mock.patch.object(cliutils, 'print_dict', mock.Mock())
def test_pool_list_with_detail(self):
self.run_command('pool-list --detail')
self.assert_called(
'GET',
'/scheduler-stats/pools/detail?backend=.%2A&host=.%2A&pool=.%2A',
)
cliutils.print_list.assert_called_with(
mock.ANY,
fields=["Name", "Host", "Backend", "Pool", 'Capabilities'])
cliutils.print_dict.assert_called_with(
{'name': 'host1@backend1#pool2', 'qos': False})
@mock.patch.object(cliutils, 'print_list', mock.Mock())
def test_pool_list_select_column(self):
self.run_command('pool-list --columns name,host')
self.assert_called(
'GET',
'/scheduler-stats/pools?backend=.%2A&host=.%2A&pool=.%2A',
'/scheduler-stats/pools/detail?backend=.%2A&host=.%2A&pool=.%2A',
)
cliutils.print_list.assert_called_with(
mock.ANY,

View File

@ -3503,7 +3503,9 @@ def _print_dict(data_dict):
@cliutils.arg(
'--detail', '--detailed',
action='store_true',
help='Show detailed information about pools. (Default=False)')
help='Show detailed information about pools. If this parameter is set '
'to True, --columns parameter will be ignored if present. '
'(Default=False)')
@cliutils.arg(
'--share-type', '--share_type',
'--share-type-id', '--share_type_id',
@ -3528,12 +3530,19 @@ def do_pool_list(cs, args):
else:
fields = ["Name", "Host", "Backend", "Pool"]
pools = cs.pools.list(detailed=args.detail, search_opts=search_opts)
if args.columns is not None:
fields = _split_columns(columns=args.columns)
pools = cs.pools.list(detailed=True, search_opts=search_opts)
pools = cs.pools.list(detailed=args.detail, search_opts=search_opts)
cliutils.print_list(pools, fields=fields)
if args.detail:
for info in pools:
backend = dict()
backend['name'] = info.name
backend.update(info.capabilities)
cliutils.print_dict(backend)
else:
cliutils.print_list(pools, fields=fields)
@cliutils.arg('share', metavar='<share>',

View File

@ -0,0 +1,4 @@
---
fixes:
- Fix Manila pool-list --column reports nothing for capabilities, And
also format the detail contents.