Adding missing CLI command congress policy rule show
Change-Id: Ic78bc07d9d353c7b71947f1225ae6776878ba256 Closes-bug: 1379466
This commit is contained in:
parent
d8d9adc67a
commit
f5e0a70b38
|
@ -252,3 +252,29 @@ class ListPolicyRows(lister.Lister):
|
|||
for i in xrange(0, len(results[0]['data']))]
|
||||
self.log.debug("Columns: " + str(columns))
|
||||
return (columns, (x['data'] for x in results))
|
||||
|
||||
|
||||
class ShowPolicyRule(show.ShowOne):
|
||||
"""Show a policy rule."""
|
||||
|
||||
log = logging.getLogger(__name__ + '.ShowPolicyRule')
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowPolicyRule, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'policy_name',
|
||||
metavar="<policy-name>",
|
||||
help="Name or identifier of the policy")
|
||||
parser.add_argument(
|
||||
'id',
|
||||
metavar="<rule>",
|
||||
help="Policy rule id")
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug('take_action(%s)' % parsed_args)
|
||||
client = self.app.client_manager.congressclient
|
||||
data = client.show_policy_rule(parsed_args.policy_name,
|
||||
parsed_args.id)
|
||||
return zip(*sorted(six.iteritems(data)))
|
||||
|
|
|
@ -289,3 +289,29 @@ class TestSimulatePolicy(common.TestCongressBase):
|
|||
args['query'] = query
|
||||
args['trace'] = True
|
||||
lister.assert_called_with(policy_name, 'simulate', args)
|
||||
|
||||
|
||||
class TestGet(common.TestCongressBase):
|
||||
|
||||
def test_create_policy_rule(self):
|
||||
policy_name = 'classification'
|
||||
rule = "p(x) :- q(x)"
|
||||
id = "e531f2b3-3d97-42c0-b3b5-b7b6ab532018"
|
||||
response = {"comment": "None",
|
||||
"id": id,
|
||||
"rule": rule}
|
||||
|
||||
arglist = [policy_name, id]
|
||||
verifylist = [
|
||||
('policy_name', policy_name),
|
||||
('id', id),
|
||||
]
|
||||
|
||||
mocker = mock.Mock(return_value=response)
|
||||
self.app.client_manager.congressclient.show_policy_rule = mocker
|
||||
cmd = policy.ShowPolicyRule(self.app, self.namespace)
|
||||
parsed_args = self.check_parser(cmd, arglist, verifylist)
|
||||
result = list(cmd.take_action(parsed_args))
|
||||
filtered = [('comment', 'id', 'rule'),
|
||||
('None', id, rule)]
|
||||
self.assertEqual(filtered, result)
|
||||
|
|
|
@ -64,6 +64,11 @@ class Client(object):
|
|||
self.policy_rules_path % (policy_name, rule_id))
|
||||
return body
|
||||
|
||||
def show_policy_rule(self, policy_name, rule_id):
|
||||
resp, body = self.httpclient.get(
|
||||
self.policy_rules_path % (policy_name, rule_id))
|
||||
return body
|
||||
|
||||
def list_policy_rows(self, policy_name, table, trace=None):
|
||||
if trace:
|
||||
query = self.policy_rows_trace
|
||||
|
|
|
@ -30,6 +30,7 @@ openstack.cli.extension =
|
|||
openstack.congressclient.v1 =
|
||||
congress_policy_rule_create = congressclient.osc.v1.policy:CreatePolicyRule
|
||||
congress_policy_rule_delete = congressclient.osc.v1.policy:DeletePolicyRule
|
||||
congress_policy_rule_show = congressclient.osc.v1.policy:ShowPolicyRule
|
||||
congress_policy_rule_list = congressclient.osc.v1.policy:ListPolicyRules
|
||||
congress_policy_list = congressclient.osc.v1.policy:ListPolicy
|
||||
congress_policy_row_list = congressclient.osc.v1.policy:ListPolicyRows
|
||||
|
|
Loading…
Reference in New Issue