summaryrefslogtreecommitdiff
path: root/glanceclient
diff options
context:
space:
mode:
authorCyril Roelandt <cyril@redhat.com>2018-05-03 15:54:00 +0200
committerCyril Roelandt <cyril@redhat.com>2018-05-31 18:52:20 +0200
commitabfe0f4bf3295a4bc807b7e4e6b46a16061b29de (patch)
tree545a57d538bae1e50197694893ffa7f662cd37af /glanceclient
parent1ef5e5d16976df4b48c0925cdc6c5dc0dfbfb610 (diff)
downloadpython-glanceclient-abfe0f4bf3295a4bc807b7e4e6b46a16061b29de.tar.gz
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
Diffstat (limited to 'glanceclient')
-rw-r--r--glanceclient/common/utils.py2
-rw-r--r--glanceclient/tests/unit/test_utils.py38
2 files changed, 40 insertions, 0 deletions
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py
index bed25b9..dee9978 100644
--- a/glanceclient/common/utils.py
+++ b/glanceclient/common/utils.py
@@ -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():
diff --git a/glanceclient/tests/unit/test_utils.py b/glanceclient/tests/unit/test_utils.py
index a63ee80..3ef585a 100644
--- a/glanceclient/tests/unit/test_utils.py
+++ b/glanceclient/tests/unit/test_utils.py
@@ -141,6 +141,44 @@ class TestUtils(testtools.TestCase):
''',
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())
+
def test_unicode_key_value_to_string(self):
src = {u'key': u'\u70fd\u7231\u5a77'}
expected = {'key': '\xe7\x83\xbd\xe7\x88\xb1\xe5\xa9\xb7'}