From 875cf42fffc6f08e84d28a896c966deaa1ab5089 Mon Sep 17 00:00:00 2001 From: Gary Kotton Date: Mon, 6 Jan 2014 01:26:58 -0800 Subject: [PATCH] Ensure that the diagnostics are user friendly In the case when the value is a dictionary or array or longer than the line then the diagnostics output will automatically wrap around to ensure that the output is user friendly. Part of the blueprint v3-diagnostics Change-Id: Ia158fd99aeb0e6296fb232e881d0f01a13407dfc Closes-bug: #1266402 --- novaclient/tests/test_utils.py | 25 +++++++++++++++++++++++++ novaclient/v1_1/shell.py | 2 +- novaclient/v3/shell.py | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/novaclient/tests/test_utils.py b/novaclient/tests/test_utils.py index d85175591..489be359a 100644 --- a/novaclient/tests/test_utils.py +++ b/novaclient/tests/test_utils.py @@ -125,6 +125,31 @@ class _FakeResult(object): class PrintResultTestCase(test_utils.TestCase): + @mock.patch('sys.stdout', six.StringIO()) + def test_print_dict(self): + dict = {'key': 'value'} + utils.print_dict(dict) + self.assertEqual(sys.stdout.getvalue(), + '+----------+-------+\n' + '| Property | Value |\n' + '+----------+-------+\n' + '| key | value |\n' + '+----------+-------+\n') + + @mock.patch('sys.stdout', six.StringIO()) + def test_print_dict_wrap(self): + dict = {'key1': 'not wrapped', + 'key2': 'this will be wrapped'} + utils.print_dict(dict, wrap=16) + self.assertEqual(sys.stdout.getvalue(), + '+----------+--------------+\n' + '| Property | Value |\n' + '+----------+--------------+\n' + '| key1 | not wrapped |\n' + '| key2 | this will be |\n' + '| | wrapped |\n' + '+----------+--------------+\n') + @mock.patch('sys.stdout', six.StringIO()) def test_print_list_sort_by_str(self): objs = [_FakeResult("k1", 1), diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 0f7ffc241..806839c29 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -1360,7 +1360,7 @@ def do_unshelve(cs, args): def do_diagnostics(cs, args): """Retrieve server diagnostics.""" server = _find_server(cs, args.server) - utils.print_dict(cs.servers.diagnostics(server)[1]) + utils.print_dict(cs.servers.diagnostics(server)[1], wrap=80) @utils.arg('server', metavar='', help='Name or ID of server.') diff --git a/novaclient/v3/shell.py b/novaclient/v3/shell.py index 8eaf2cb1d..65d80ca5e 100644 --- a/novaclient/v3/shell.py +++ b/novaclient/v3/shell.py @@ -1201,7 +1201,7 @@ def do_unrescue(cs, args): def do_diagnostics(cs, args): """Retrieve server diagnostics.""" server = _find_server(cs, args.server) - utils.print_dict(cs.servers.diagnostics(server)[1]) + utils.print_dict(cs.servers.diagnostics(server)[1], wrap=80) @utils.arg('server', metavar='', help='Name or ID of server.')