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
This commit is contained in:
Gary Kotton 2014-01-06 01:26:58 -08:00
parent 5c62630a9d
commit 875cf42fff
3 changed files with 27 additions and 2 deletions

View File

@ -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),

View File

@ -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='<server>', help='Name or ID of server.')

View File

@ -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='<server>', help='Name or ID of server.')