summaryrefslogtreecommitdiff
path: root/glanceclient
diff options
context:
space:
mode:
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'}