Image show: print human readable string when the virtual size is unknown
Currently, when the virtual size of an image is not known, "None" is displayed. To a regular user, it feels like a programming error. We try and make things clearer by using a "human readable" string instead. Change-Id: Id7b8799356857d9bc58cc8a3677024fe1a7f4f56 Partial-Bug: #1665037
This commit is contained in:
parent
1ef5e5d169
commit
abfe0f4bf3
glanceclient
@ -421,6 +421,8 @@ def print_image(image_obj, human_readable=False, max_col_width=None):
|
||||
ignore = ['self', 'access', 'file', 'schema']
|
||||
image = dict([item for item in image_obj.items()
|
||||
if item[0] not in ignore])
|
||||
if 'virtual_size' in image:
|
||||
image['virtual_size'] = image.get('virtual_size') or 'Not available'
|
||||
if human_readable:
|
||||
image['size'] = make_size_human_readable(image['size'])
|
||||
if str(max_col_width).isdigit():
|
||||
|
@ -138,6 +138,44 @@ class TestUtils(testtools.TestCase):
|
||||
+--------------------------------------+--------------------------------------+
|
||||
| b8e1c57e-907a-4239-aed8-0df8e54b8d2d | ['Name1', 'Tag_123', 'veeeery long'] |
|
||||
+--------------------------------------+--------------------------------------+
|
||||
''',
|
||||
output_list.getvalue())
|
||||
|
||||
def test_print_image_virtual_size_available(self):
|
||||
image = {'id': '42', 'virtual_size': 1337}
|
||||
saved_stdout = sys.stdout
|
||||
try:
|
||||
sys.stdout = output_list = six.StringIO()
|
||||
utils.print_image(image)
|
||||
finally:
|
||||
sys.stdout = saved_stdout
|
||||
|
||||
self.assertEqual('''\
|
||||
+--------------+-------+
|
||||
| Property | Value |
|
||||
+--------------+-------+
|
||||
| id | 42 |
|
||||
| virtual_size | 1337 |
|
||||
+--------------+-------+
|
||||
''',
|
||||
output_list.getvalue())
|
||||
|
||||
def test_print_image_virtual_size_not_available(self):
|
||||
image = {'id': '42', 'virtual_size': None}
|
||||
saved_stdout = sys.stdout
|
||||
try:
|
||||
sys.stdout = output_list = six.StringIO()
|
||||
utils.print_image(image)
|
||||
finally:
|
||||
sys.stdout = saved_stdout
|
||||
|
||||
self.assertEqual('''\
|
||||
+--------------+---------------+
|
||||
| Property | Value |
|
||||
+--------------+---------------+
|
||||
| id | 42 |
|
||||
| virtual_size | Not available |
|
||||
+--------------+---------------+
|
||||
''',
|
||||
output_list.getvalue())
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user