diff --git a/senlinclient/osc/v1/policy_type.py b/senlinclient/osc/v1/policy_type.py index 9f6b7be..61350d2 100644 --- a/senlinclient/osc/v1/policy_type.py +++ b/senlinclient/osc/v1/policy_type.py @@ -13,8 +13,13 @@ """Clustering v1 policy type action implementations""" import logging +import six from cliff import lister +from openstack import exceptions as sdk_exc +from openstackclient.common import exceptions as exc +from senlinclient.common import format_utils +from senlinclient.common.i18n import _ class PolicyTypeList(lister.Lister): @@ -33,3 +38,31 @@ class PolicyTypeList(lister.Lister): columns = ['name'] rows = sorted([t.name] for t in types) return columns, rows + + +class PolicyTypeShow(format_utils.YamlFormat): + """Get the details about a policy type.""" + + log = logging.getLogger(__name__ + ".PolicyTypeShow") + + def get_parser(self, prog_name): + parser = super(PolicyTypeShow, self).get_parser(prog_name) + parser.add_argument( + 'type_name', + metavar='', + help=_('Policy type to retrieve') + ) + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)", parsed_args) + senlin_client = self.app.client_manager.clustering + + try: + res = senlin_client.get_policy_type(parsed_args.type_name) + except sdk_exc.ResourceNotFound: + raise exc.CommandError(_('Policy Type not found: %s') + % parsed_args.type_name) + rows = list(six.itervalues(res)) + columns = list(six.iterkeys(res)) + return columns, rows diff --git a/senlinclient/tests/unit/osc/v1/test_policy_type.py b/senlinclient/tests/unit/osc/v1/test_policy_type.py index 28b00f8..84506f7 100644 --- a/senlinclient/tests/unit/osc/v1/test_policy_type.py +++ b/senlinclient/tests/unit/osc/v1/test_policy_type.py @@ -13,6 +13,8 @@ import mock from openstack.cluster.v1 import policy_type as sdk_policy_type +from openstack import exceptions as sdk_exc +from openstackclient.common import exceptions as exc from senlinclient.osc.v1 import policy_type as osc_policy_type from senlinclient.tests.unit.osc.v1 import fakes @@ -57,3 +59,34 @@ class TestPolicyTypeList(TestPolicyType): self.mock_client.policy_types.assert_called_with() self.assertEqual(self.expected_columns, columns) self.assertEqual(self.expected_rows, rows) + + +class TestPolicyTypeShow(TestPolicyType): + + response = ({'name': 'senlin.policy.deletion-1.0', + 'schema': { + 'foo': 'bar'}}) + + def setUp(self): + super(TestPolicyTypeShow, self).setUp() + self.cmd = osc_policy_type.PolicyTypeShow(self.app, None) + self.mock_client.get_policy_type = mock.Mock( + return_value=sdk_policy_type.PolicyType(self.response) + ) + + def test_policy_type_show(self): + arglist = ['os.heat.stack-1.0'] + parsed_args = self.check_parser(self.cmd, arglist, []) + self.cmd.take_action(parsed_args) + self.mock_client.get_policy_type.assert_called_once_with( + 'os.heat.stack-1.0') + + def test_policy_type_show_not_found(self): + arglist = ['senlin.policy.deletion-1.0'] + parsed_args = self.check_parser(self.cmd, arglist, []) + self.mock_client.get_policy_type.side_effect = ( + sdk_exc.ResourceNotFound()) + error = self.assertRaises(exc.CommandError, self.cmd.take_action, + parsed_args) + self.assertEqual('Policy Type not found: senlin.policy.deletion-1.0', + str(error)) diff --git a/setup.cfg b/setup.cfg index 8c6e847..7cdb437 100644 --- a/setup.cfg +++ b/setup.cfg @@ -41,6 +41,7 @@ openstack.clustering.v1 = cluster_policy_list = senlinclient.osc.v1.policy:ListPolicy cluster_policy_show = senlinclient.osc.v1.policy:ShowPolicy cluster_policy_type_list = senlinclient.osc.v1.policy_type:PolicyTypeList + cluster_policy_type_show = senlinclient.osc.v1.policy_type:PolicyTypeShow cluster_policy_update = senlinclient.osc.v1.policy:UpdatePolicy cluster_profile_create = senlinclient.osc.v1.profile:CreateProfile cluster_profile_delete = senlinclient.osc.v1.profile:DeleteProfile