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:
parent
5c62630a9d
commit
875cf42fff
@ -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),
|
||||
|
@ -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.')
|
||||
|
@ -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.')
|
||||
|
Loading…
Reference in New Issue
Block a user