Adds CLI command for show policy

Closes-Bug: #1386407
Change-Id: I230b7af1d48eba368c718aef378e725de5234391
This commit is contained in:
Amey Bhide 2015-02-23 16:01:32 -08:00
parent 9b2436d317
commit 01b0b28400
3 changed files with 50 additions and 0 deletions

View File

@ -405,3 +405,24 @@ class ShowPolicyTable(show.ShowOne):
data = client.show_policy_table(parsed_args.policy_name,
parsed_args.table_id)
return zip(*sorted(six.iteritems(data)))
class ShowPolicy(show.ShowOne):
"""Show policy properties."""
log = logging.getLogger(__name__ + '.ShowPolicy')
def get_parser(self, prog_name):
parser = super(ShowPolicy, self).get_parser(prog_name)
parser.add_argument(
'policy_name',
metavar='<policy-name>',
help="Name of policy")
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(parsed_args.policy_name)
return zip(*sorted(six.iteritems(data)))

View File

@ -46,6 +46,34 @@ class TestCreatePolicy(common.TestCongressBase):
self.assertEqual(filtered, result)
class TestShowPolicy(common.TestCongressBase):
def test_show_policy(self):
policy_id = "14f2897a-155a-4c9d-b3de-ef85c0a171d8"
policy_name = "test1"
arglist = [policy_id]
verifylist = [
('policy_name', policy_id),
]
response = {"description": "",
"id": policy_id,
"name": policy_name,
"kind": "nonrecursive",
"owner": "system",
"abbreviation": "test1"}
mocker = mock.Mock(return_value=response)
self.app.client_manager.congressclient.show_policy = mocker
cmd = policy.ShowPolicy(self.app, self.namespace)
parsed_args = self.check_parser(cmd, arglist, verifylist)
result = list(cmd.take_action(parsed_args))
filtered = [('abbreviation', 'description', 'id', 'kind', 'name',
'owner'),
(policy_name, '', policy_id, 'nonrecursive',
policy_name, 'system')]
self.assertEqual(filtered, result)
class TestDeletePolicy(common.TestCongressBase):
def test_delete_policy(self):
policy_id = 'e531f2b3-3d97-42c0-b3b5-b7b6ab532018'

View File

@ -30,6 +30,7 @@ openstack.cli.extension =
openstack.congressclient.v1 =
congress_policy_create = congressclient.osc.v1.policy:CreatePolicy
congress_policy_delete = congressclient.osc.v1.policy:DeletePolicy
congress_policy_show = congressclient.osc.v1.policy:ShowPolicy
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