Add OSC plugin for cluster policy type show
This change implements the "openstack cluster policy type show" command Based on the existing senlin command: senlin policy-type-show Change-Id: Ie103c29bfe3c48453728c3381a2b90c38a3bf236 Blueprint: senlin-support-python-openstackclient
This commit is contained in:
@@ -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='<type_name>',
|
||||
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
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user