Added pretty-print for rules
Change-Id: I959c5050fadb059ab3a5ac10dfff12c48a357e25
This commit is contained in:
parent
ba7d1420e7
commit
fb3f0cb1f3
|
@ -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):
|
||||
|
|
|
@ -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])
|
||||
|
|
Loading…
Reference in New Issue