diff --git a/cinderclient/tests/test_utils.py b/cinderclient/tests/test_utils.py index 1ba9e5ff7..cf2518f64 100644 --- a/cinderclient/tests/test_utils.py +++ b/cinderclient/tests/test_utils.py @@ -121,6 +121,21 @@ class PrintListTestCase(test_utils.TestCase): | 1 | 2 | | 3 | 4 | +---+---+ +""", 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): diff --git a/cinderclient/utils.py b/cinderclient/utils.py index fcf9f689f..330d52d8e 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)