diff --git a/congressclient/osc/v1/policy.py b/congressclient/osc/v1/policy.py index 000c598..dc0154d 100644 --- a/congressclient/osc/v1/policy.py +++ b/congressclient/osc/v1/policy.py @@ -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='', + 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))) diff --git a/congressclient/tests/v1/test_policy.py b/congressclient/tests/v1/test_policy.py index 4184e47..4ac732e 100644 --- a/congressclient/tests/v1/test_policy.py +++ b/congressclient/tests/v1/test_policy.py @@ -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' diff --git a/setup.cfg b/setup.cfg index 06dc09b..e27c257 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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