From fb3f0cb1f3fb9e4a9a66a368dbafd2fcfc3f6ee7 Mon Sep 17 00:00:00 2001 From: Tim Hinrichs Date: Thu, 11 Sep 2014 14:38:16 -0700 Subject: [PATCH] Added pretty-print for rules Change-Id: I959c5050fadb059ab3a5ac10dfff12c48a357e25 --- congressclient/osc/v1/policy.py | 18 +++++++++--------- congressclient/tests/v1/test_policy.py | 12 ++++-------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/congressclient/osc/v1/policy.py b/congressclient/osc/v1/policy.py index 7389c12..1d49a65 100644 --- a/congressclient/osc/v1/policy.py +++ b/congressclient/osc/v1/policy.py @@ -59,7 +59,6 @@ class CreatePolicyRule(show.ShowOne): client = self.app.client_manager.congressclient body = {'rule': parsed_args.rule} data = client.create_policy_rule(parsed_args.policy_name, body) - data['rule'] = _format_rule(data['rule']) return zip(*sorted(six.iteritems(data))) @@ -87,7 +86,7 @@ class DeletePolicyRule(command.Command): parsed_args.rule_id) -class ListPolicyRules(lister.Lister): +class ListPolicyRules(command.Command): """List policy rules.""" log = logging.getLogger(__name__ + '.ListPolicyRules') @@ -103,13 +102,14 @@ class ListPolicyRules(lister.Lister): def take_action(self, parsed_args): self.log.debug('take_action(%s)' % parsed_args) client = self.app.client_manager.congressclient - data = client.list_policy_rules(parsed_args.policy_name)['results'] - columns = ['id', 'comment', 'rule'] - formatters = {'PolicyRules': utils.format_list} - return (columns, - (utils.get_dict_properties(s, columns, - formatters=formatters) - for s in data)) + results = client.list_policy_rules(parsed_args.policy_name)['results'] + for result in results: + print("// ID: %s" % str(result['id'])) + if result['comment'] != "None": + print("// %s" % str(result['comment'])) + print(result['rule']) + print('') + return 0 class ListPolicyTables(lister.Lister): diff --git a/congressclient/tests/v1/test_policy.py b/congressclient/tests/v1/test_policy.py index 7c1efe2..9f30c79 100644 --- a/congressclient/tests/v1/test_policy.py +++ b/congressclient/tests/v1/test_policy.py @@ -46,8 +46,7 @@ class TestCreatePolicyRule(common.TestCongressBase): parsed_args = self.check_parser(cmd, arglist, verifylist) result = list(cmd.take_action(parsed_args)) filtered = [('comment', 'id', 'rule'), - ('None', 'e531f2b3-3d97-42c0-b3b5-b7b6ab532018', - policy._format_rule(rule))] + ('None', 'e531f2b3-3d97-42c0-b3b5-b7b6ab532018', rule)] self.assertEqual(filtered, result) @@ -94,10 +93,9 @@ class TestListPolicyRules(common.TestCongressBase): cmd = policy.ListPolicyRules(self.app, self.namespace) parsed_args = self.check_parser(cmd, arglist, verifylist) - result = cmd.take_action(parsed_args) + cmd.take_action(parsed_args) lister.assert_called_with(policy_name) - self.assertEqual(['id', 'comment', 'rule'], result[0]) class TestListPolicy(common.TestCongressBase): @@ -167,10 +165,9 @@ class TestListPolicyRows(common.TestCongressBase): cmd = policy.ListPolicyRows(self.app, self.namespace) parsed_args = self.check_parser(cmd, arglist, verifylist) - result = cmd.take_action(parsed_args) + cmd.take_action(parsed_args) lister.assert_called_with(policy_name, table_name, False) - self.assertEqual(['Col0', 'Col1'], result[0]) def test_list_policy_rules_trace(self): policy_name = 'classification' @@ -194,7 +191,6 @@ class TestListPolicyRows(common.TestCongressBase): cmd = policy.ListPolicyRows(self.app, self.namespace) parsed_args = self.check_parser(cmd, arglist, verifylist) - result = cmd.take_action(parsed_args) + cmd.take_action(parsed_args) lister.assert_called_with(policy_name, table_name, True) - self.assertEqual(['Col0', 'Col1'], result[0])