summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-03-16 21:36:02 +0000
committerGerrit Code Review <review@openstack.org>2015-03-16 21:36:02 +0000
commit7971b36c523a56d6aa243574aed7934a9a8db6f3 (patch)
tree4bada0b95986076db5739592bd0c00d6e1af8aa5
parent425565b79cbd3541df39f5bbb31912db09a57357 (diff)
parent0f73c5fb8ab593da7e332ade273e7da31ea8e303 (diff)
downloadpython-cinderclient-7971b36c523a56d6aa243574aed7934a9a8db6f3.tar.gz
Merge "cinder list now prints dash '-' when data is None"
-rw-r--r--cinderclient/tests/test_utils.py15
-rw-r--r--cinderclient/utils.py2
2 files changed, 17 insertions, 0 deletions
diff --git a/cinderclient/tests/test_utils.py b/cinderclient/tests/test_utils.py
index 1ba9e5f..cf2518f 100644
--- a/cinderclient/tests/test_utils.py
+++ b/cinderclient/tests/test_utils.py
@@ -123,6 +123,21 @@ class PrintListTestCase(test_utils.TestCase):
+---+---+
""", cso.read())
+ def test_print_list_with_None_data(self):
+ Row = collections.namedtuple('Row', ['a', 'b'])
+ to_print = [Row(a=3, b=None), Row(a=1, b=2)]
+ with CaptureStdout() as cso:
+ utils.print_list(to_print, ['a', 'b'])
+ # Output should be sorted by the first key (a)
+ self.assertEqual("""\
++---+---+
+| a | b |
++---+---+
+| 1 | 2 |
+| 3 | - |
++---+---+
+""", cso.read())
+
def test_print_list_with_list_sortby(self):
Row = collections.namedtuple('Row', ['a', 'b'])
to_print = [Row(a=4, b=3), Row(a=2, b=1)]
diff --git a/cinderclient/utils.py b/cinderclient/utils.py
index fcf9f68..330d52d 100644
--- a/cinderclient/utils.py
+++ b/cinderclient/utils.py
@@ -139,6 +139,8 @@ def print_list(objs, fields, formatters=None, sortby_index=0):
data = o[field]
else:
data = getattr(o, field_name, '')
+ if data is None:
+ data = '-'
row.append(data)
pt.add_row(row)