From 22a413bcd7391f6df11cf8ee0e340babb6f339ad Mon Sep 17 00:00:00 2001 From: Shrirang Phadke Date: Tue, 7 Jan 2014 22:08:28 +0530 Subject: [PATCH] Fixes ambiguous cli output between "None" and NoneType Print hyphen(-) in python client output when attribute value is not set(NoneType) so that it is distinguishable between "None" string and NoneType value. Cherry-Pick: I5ec0f39f13aca45fa95ddb59472c20207c63bf91 Change-Id: I8a907e7453df711605d28bb97492f747adc282e0 Closes-Bug: #1266414 --- saharaclient/nova/utils.py | 4 ++++ saharaclient/tests/unit/nova/test_shell.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/saharaclient/nova/utils.py b/saharaclient/nova/utils.py index 8d4bc16c..c50e975e 100644 --- a/saharaclient/nova/utils.py +++ b/saharaclient/nova/utils.py @@ -152,6 +152,8 @@ def print_list(objs, fields, formatters={}, sortby_index=None): else: field_name = field.lower().replace(' ', '_') data = getattr(o, field_name, '') + if data is None: + data = '-' row.append(data) pt.add_row(row) @@ -222,6 +224,8 @@ def print_dict(d, dict_property="Property", dict_value="Value", wrap=0): pt.add_row([col1, line]) col1 = '' else: + if v is None: + v = '-' pt.add_row([k, v]) print(strutils.safe_encode(pt.get_string())) diff --git a/saharaclient/tests/unit/nova/test_shell.py b/saharaclient/tests/unit/nova/test_shell.py index 8ba3a659..31598a40 100644 --- a/saharaclient/tests/unit/nova/test_shell.py +++ b/saharaclient/tests/unit/nova/test_shell.py @@ -278,7 +278,7 @@ class ShellTest(utils.TestCase): '+------+------------+----------+------+-------------+\n' '| name | id | username | tags | description |\n' '+------+------------+----------+------+-------------+\n' - '| fake | aaa-bb-ccc | you | | None |\n' + '| fake | aaa-bb-ccc | you | | - |\n' '+------+------------+----------+------+-------------+\n' ) self.make_env()