From 0f73c5fb8ab593da7e332ade273e7da31ea8e303 Mon Sep 17 00:00:00 2001
From: yatin karel <yatin.karel@nectechnologies.in>
Date: Mon, 16 Mar 2015 23:26:12 +0530
Subject: [PATCH] cinder list now prints dash '-' when data is None

cinder list used to print None when volume was created without name.
Now it prints '-' dash when display_name is None

Closes-Bug: #1422244
Change-Id: I195ccc37fe96dbb54a0460527fabf55146170bc7
---
 cinderclient/tests/test_utils.py | 15 +++++++++++++++
 cinderclient/utils.py            |  2 ++
 2 files changed, 17 insertions(+)

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)