Fix profile/policy schema calls
This patch is the client side fix for profile-type-schema and policy-type-schema. Depends-On: I61a406ec941f902cb88e4ec521a42af05bb5a93a Change-Id: I3a932c47b3f72bc256ad49d1994301714e7df398
This commit is contained in:
@@ -71,31 +71,35 @@ class ShellTest(testtools.TestCase):
|
||||
self.assertTrue(client.profile_types.called)
|
||||
|
||||
@mock.patch.object(utils, 'format_output')
|
||||
def test_do_profile_type_schema(self, mock_format):
|
||||
def test_do_profile_type_get(self, mock_format):
|
||||
client = mock.Mock()
|
||||
schema = {'foo': 'bar'}
|
||||
client.get_profile_type_schema = mock.MagicMock(return_value=schema)
|
||||
args = {
|
||||
'format': 'list',
|
||||
'profile_type': 'os.nova.server'
|
||||
fake_pt = mock.Mock()
|
||||
fake_pt.to_dict.return_value = {'foo': 'bar'}
|
||||
client.get_profile_type = mock.Mock(return_value=fake_pt)
|
||||
args_dict = {
|
||||
'format': 'json',
|
||||
'type_name': 'os.nova.server'
|
||||
}
|
||||
args = self._make_args(args)
|
||||
sh.do_profile_type_schema(client, args)
|
||||
mock_format.assert_called_with(schema, format=args.format)
|
||||
client.get_profile_type_schema.assert_called_with(
|
||||
args = self._make_args(args_dict)
|
||||
sh.do_profile_type_show(client, args)
|
||||
mock_format.assert_called_with({'foo': 'bar'}, format=args.format)
|
||||
client.get_profile_type.assert_called_with(
|
||||
'os.nova.server')
|
||||
args.format = None
|
||||
sh.do_profile_type_schema(client, args)
|
||||
mock_format.assert_called_with(schema)
|
||||
sh.do_profile_type_show(client, args)
|
||||
mock_format.assert_called_with({'foo': 'bar'})
|
||||
|
||||
def test_do_profile_type_schema_type_not_found(self):
|
||||
client = mock.Mock()
|
||||
args = {'profile_type': 'wrong_type'}
|
||||
args = {
|
||||
'type_name': 'wrong_type',
|
||||
'format': 'json'
|
||||
}
|
||||
args = self._make_args(args)
|
||||
ex = exc.HTTPNotFound
|
||||
client.get_profile_type_schema = mock.MagicMock(side_effect=ex)
|
||||
client.get_profile_type = mock.Mock(side_effect=ex)
|
||||
ex = self.assertRaises(exc.CommandError,
|
||||
sh.do_profile_type_schema,
|
||||
sh.do_profile_type_show,
|
||||
client, args)
|
||||
self.assertEqual(_('Profile Type wrong_type not found.'),
|
||||
six.text_type(ex))
|
||||
|
||||
@@ -42,9 +42,8 @@ class Client(object):
|
||||
def profile_types(self, **kwargs):
|
||||
return self.list(models.ProfileType, paginated=False)
|
||||
|
||||
def get_profile_type_schema(self, value):
|
||||
params = {'profile_type': value}
|
||||
return self.get(models.ProfileTypeSchema, params)
|
||||
def get_profile_type(self, value):
|
||||
return self.get(models.ProfileType, dict(name=value))
|
||||
|
||||
def profiles(self, **queries):
|
||||
return self.list(models.Profile, **queries)
|
||||
@@ -66,9 +65,8 @@ class Client(object):
|
||||
def policy_types(self, **kwargs):
|
||||
return self.list(models.PolicyType, paginated=False)
|
||||
|
||||
def get_policy_type_schema(self, value):
|
||||
params = {'policy_type': value}
|
||||
return self.get(models.PolicyTypeSchema, params)
|
||||
def get_policy_type(self, value):
|
||||
return self.get(models.PolicyType, dict(name=value))
|
||||
|
||||
def webhooks(self, **queries):
|
||||
return self.list(models.Webhook, **queries)
|
||||
|
||||
@@ -44,7 +44,8 @@ class BuildInfo(resource.Resource):
|
||||
|
||||
|
||||
class ProfileType(resource.Resource):
|
||||
resource_key = None
|
||||
id_attribute = 'name'
|
||||
resource_key = 'profile_type'
|
||||
resources_key = 'profile_types'
|
||||
base_path = '/profile-types'
|
||||
service = cluster_service.ClusterService()
|
||||
@@ -55,29 +56,7 @@ class ProfileType(resource.Resource):
|
||||
|
||||
# Properties
|
||||
name = resource.prop('name')
|
||||
|
||||
|
||||
class ProfileTypeSchema(resource.Resource):
|
||||
base_path = '/profile-types/%(profile_type)s'
|
||||
service = cluster_service.ClusterService()
|
||||
|
||||
# Capabilities
|
||||
allow_retrieve = True
|
||||
|
||||
# Properties
|
||||
schema = resource.prop('schema', type=dict)
|
||||
|
||||
|
||||
class ProfileTypeTemplate(resource.Resource):
|
||||
resource_key = 'template'
|
||||
base_path = '/profile-types/%(profile_type)s/template'
|
||||
service = cluster_service.ClusterService()
|
||||
|
||||
# Capabilities
|
||||
allow_retrieve = True
|
||||
|
||||
# Properties
|
||||
template = resource.prop('template', type=dict)
|
||||
schema = resource.prop('schema')
|
||||
|
||||
|
||||
class Profile(resource.Resource):
|
||||
@@ -119,6 +98,8 @@ class Profile(resource.Resource):
|
||||
|
||||
|
||||
class PolicyType(resource.Resource):
|
||||
id_attribute = 'name'
|
||||
resource_key = 'policy_type'
|
||||
resources_key = 'policy_types'
|
||||
base_path = '/policy-types'
|
||||
service = cluster_service.ClusterService()
|
||||
@@ -129,29 +110,7 @@ class PolicyType(resource.Resource):
|
||||
|
||||
# Properties
|
||||
name = resource.prop('name')
|
||||
|
||||
|
||||
class PolicyTypeSchema(resource.Resource):
|
||||
base_path = '/policy-types/%(policy_type)s'
|
||||
service = cluster_service.ClusterService()
|
||||
|
||||
# Capabilities
|
||||
allow_retrieve = True
|
||||
|
||||
# Properties
|
||||
schema = resource.prop('schema', type=dict)
|
||||
|
||||
|
||||
class PolicyTypeTemplate(resource.Resource):
|
||||
resource_key = 'template'
|
||||
base_path = '/policy-types/%(policy_type)s/template'
|
||||
service = cluster_service.ClusterService()
|
||||
|
||||
# Capabilities
|
||||
allow_retrieve = True
|
||||
|
||||
# Properties
|
||||
template = resource.prop('template', type=dict)
|
||||
schema = resource.prop('schema')
|
||||
|
||||
|
||||
class Policy(resource.Resource):
|
||||
|
||||
@@ -12,12 +12,9 @@
|
||||
|
||||
import logging
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
|
||||
from senlinclient.common import exc
|
||||
from senlinclient.common.i18n import _
|
||||
from senlinclient.common import utils
|
||||
from senlinclient.v1 import models
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -50,25 +47,25 @@ def do_profile_type_list(sc, args=None):
|
||||
utils.print_list(types, ['name'], sortby_index=0)
|
||||
|
||||
|
||||
@utils.arg('profile_type', metavar='<PROFILE_TYPE>',
|
||||
help=_('Profile type to generate a template for.'))
|
||||
@utils.arg('type_name', metavar='<TYPE_NAME>',
|
||||
help=_('Profile type to retrieve.'))
|
||||
@utils.arg('-F', '--format', metavar='<FORMAT>',
|
||||
help=_("The template output format, one of: %s.")
|
||||
% ', '.join(utils.supported_formats.keys()))
|
||||
def do_profile_type_schema(sc, args):
|
||||
'''Get the spec of a profile type.'''
|
||||
def do_profile_type_show(sc, args):
|
||||
'''Get the details about a profile type.'''
|
||||
try:
|
||||
schema = sc.get_profile_type_schema(args.profile_type)
|
||||
res = sc.get_profile_type(args.type_name)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError(
|
||||
_('Profile Type %s not found.') % args.profile_type)
|
||||
_('Profile Type %s not found.') % args.type_name)
|
||||
|
||||
schema = dict(schema)
|
||||
pt = res.to_dict()
|
||||
|
||||
if args.format:
|
||||
print(utils.format_output(schema, format=args.format))
|
||||
print(utils.format_output(pt, format=args.format))
|
||||
else:
|
||||
print(utils.format_output(schema))
|
||||
print(utils.format_output(pt))
|
||||
|
||||
|
||||
def _short_id(obj):
|
||||
@@ -224,38 +221,24 @@ def do_policy_type_list(sc, args):
|
||||
utils.print_list(types, ['name'], sortby_index=0)
|
||||
|
||||
|
||||
@utils.arg('policy_type', metavar='<POLICY_TYPE>',
|
||||
help=_('Policy type to get the details for.'))
|
||||
def do_policy_type_show(sc, args):
|
||||
'''Show the policy type.'''
|
||||
try:
|
||||
params = {'policy_type': args.policy_type}
|
||||
policy_type = sc.get(models.PolicyTypeSchema, params)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError(
|
||||
_('Policy Type not found: %s') % args.policy_type)
|
||||
else:
|
||||
print(jsonutils.dumps(policy_type, indent=2))
|
||||
|
||||
|
||||
@utils.arg('policy_type', metavar='<POLICY_TYPE>',
|
||||
help=_('Policy type to generate a template for.'))
|
||||
@utils.arg('type_name', metavar='<TYPE_NAME>',
|
||||
help=_('Policy type to retrieve.'))
|
||||
@utils.arg('-F', '--format', metavar='<FORMAT>',
|
||||
help=_("The template output format, one of: %s.")
|
||||
% ', '.join(utils.supported_formats.keys()))
|
||||
def do_policy_type_schema(sc, args):
|
||||
'''Get the spec of a policy type.'''
|
||||
def do_policy_type_show(sc, args):
|
||||
'''Get the details about a policy type.'''
|
||||
try:
|
||||
schema = sc.get_policy_type_schema(args.policy_type)
|
||||
res = sc.get_policy_type(args.type_name)
|
||||
except exc.HTTPNotFound:
|
||||
raise exc.CommandError(
|
||||
_('Policy type %s not found.') % args.policy_type)
|
||||
_('Policy type %s not found.') % args.type_name)
|
||||
|
||||
schema = dict(schema)
|
||||
pt = res.to_dict()
|
||||
if args.format:
|
||||
print(utils.format_output(schema, format=args.format))
|
||||
print(utils.format_output(pt, format=args.format))
|
||||
else:
|
||||
print(utils.format_output(schema))
|
||||
print(utils.format_output(pt))
|
||||
|
||||
|
||||
# WEBHOOKS
|
||||
|
||||
Reference in New Issue
Block a user