From 2c525e9178a8fd126a2289fec1c565e565449b4a Mon Sep 17 00:00:00 2001 From: Haiwei Xu Date: Tue, 15 Dec 2015 17:42:18 +0900 Subject: [PATCH] Don't show show_deleted column in node-list when not needed If user wants to show the nodes which are already deleted they can use '-D' in node-list, but if '-D' is not set, 'show_deleted' column should not shown in node-list. 'show_deleted' option should always be True/False, not None. Change-Id: I83ace7515f31bcb30c83b9f0147f33dd94c72baf Closes-bug: #1526177 --- senlinclient/tests/unit/v1/test_shell.py | 49 ++++++++++++++++++++++++ senlinclient/v1/shell.py | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/senlinclient/tests/unit/v1/test_shell.py b/senlinclient/tests/unit/v1/test_shell.py index e15bea48..ab9f91b6 100644 --- a/senlinclient/tests/unit/v1/test_shell.py +++ b/senlinclient/tests/unit/v1/test_shell.py @@ -775,3 +775,52 @@ class ShellTest(testtools.TestCase): sh.do_cluster_node_del(client, args) client.cluster_del_nodes.assert_called_once_with('cluster_id', node_ids) + + @mock.patch.object(utils, 'print_list') + def test_do_node_list(self, mock_print): + client = mock.Mock() + fields = ['id', 'name', 'status', 'cluster_id', 'physical_id', + 'profile_name', 'created_time', 'updated_time', + 'deleted_time'] + args = { + 'show_deleted': True, + 'cluster': 'cluster1', + 'sort_keys': 'name', + 'sort_dir': 'asc', + 'limit': 20, + 'marker': 'marker_id', + 'global_project': True, + 'filters': ['status=active'], + 'full_id': True, + } + queries = { + 'show_deleted': True, + 'cluster_id': 'cluster1', + 'sort_keys': 'name', + 'sort_dir': 'asc', + 'limit': 20, + 'marker': 'marker_id', + 'global_project': True, + 'status': 'active', + } + args = self._make_args(args) + nodes = mock.Mock() + client.nodes.return_value = nodes + short_id = mock.Mock() + sh._short_id = short_id + short_cluster_id = mock.Mock() + sh._short_cluster_id = short_cluster_id + short_physical_id = mock.Mock() + sh._short_physical_id = short_physical_id + formatters = {} + sh.do_node_list(client, args) + mock_print.assert_called_once_with(nodes, fields, + formatters=formatters, + sortby_index=None) + client.nodes.assert_called_once_with(**queries) + # wrong sort key + args.sort_keys = 'name;wrong_key' + ex = exc.CommandError + ex = self.assertRaises(ex, sh.do_node_list, client, args) + msg = _('Invalid sorting key: wrong_key') + self.assertEqual(msg, six.text_type(ex)) diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index e2014236..e34995a9 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -1033,7 +1033,7 @@ def do_node_list(sc, args): if args.filters: queries.update(utils.format_parameters(args.filters)) - if args.show_deleted is not None: + if args.show_deleted: fields.append('deleted_time') sortby_index = None