diff --git a/novaclient/tests/unit/test_utils.py b/novaclient/tests/unit/test_utils.py index 8bcb2bfcd..d4eff35c2 100644 --- a/novaclient/tests/unit/test_utils.py +++ b/novaclient/tests/unit/test_utils.py @@ -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): diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py index 32ba61164..c8ef86bad 100644 --- a/novaclient/v2/shell.py +++ b/novaclient/v2/shell.py @@ -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(