Improve hypervisor-show print list
Current hypervisor-show <hostname> command does not properly list when there is a long list of cpu info feature. The long list of cpu info feature has comma-separated values. Because of this user is not able to read the print out properly. print_dict() has been changed to show a list with comma-separated values properly. Change-Id: Icc53439cecd3b5eee2340267a0447ce209d7b653 Closes-Bug: #1466435
This commit is contained in:
parent
39020950d6
commit
a061470a8e
@ -266,6 +266,20 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'+----------+----------------+\n',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
def test_print_large_dict_list(self):
|
||||
dict = {'k': ['foo1', 'bar1', 'foo2', 'bar2',
|
||||
'foo3', 'bar3', 'foo4', 'bar4']}
|
||||
utils.print_dict(dict, wrap=40)
|
||||
self.assertEqual(
|
||||
'+----------+------------------------------------------+\n'
|
||||
'| Property | Value |\n'
|
||||
'+----------+------------------------------------------+\n'
|
||||
'| k | ["foo1", "bar1", "foo2", "bar2", "foo3", |\n'
|
||||
'| | "bar3", "foo4", "bar4"] |\n'
|
||||
'+----------+------------------------------------------+\n',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
|
||||
class FlattenTestCase(test_utils.TestCase):
|
||||
def test_flattening(self):
|
||||
|
@ -3667,10 +3667,14 @@ def do_hypervisor_servers(cs, args):
|
||||
'hypervisor',
|
||||
metavar='<hypervisor>',
|
||||
help=_('Name or ID of the hypervisor to show the details of.'))
|
||||
@cliutils.arg(
|
||||
'--wrap', dest='wrap', metavar='<integer>', default=40,
|
||||
help=_('Wrap the output to a specified length. '
|
||||
'Default is 40 or 0 to disable'))
|
||||
def do_hypervisor_show(cs, args):
|
||||
"""Display the details of the specified hypervisor."""
|
||||
hyper = _find_hypervisor(cs, args.hypervisor)
|
||||
utils.print_dict(utils.flatten_dict(hyper._info))
|
||||
utils.print_dict(utils.flatten_dict(hyper._info), wrap=int(args.wrap))
|
||||
|
||||
|
||||
@cliutils.arg(
|
||||
|
Loading…
Reference in New Issue
Block a user