Merge "osc resource-type-show description option"
This commit is contained in:
commit
e95df61c64
@ -42,11 +42,21 @@ class ResourceTypeShow(format_utils.YamlFormat):
|
||||
metavar='<template-type>',
|
||||
help=_('Optional template type to generate, hot or cfn')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--long',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help=_('Show resource type with corresponding description.')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.log.debug("take_action(%s)", parsed_args)
|
||||
|
||||
if parsed_args.template_type is not None and parsed_args.long:
|
||||
msg = _('Cannot use --template-type and --long in one time.')
|
||||
raise exc.CommandError(msg)
|
||||
|
||||
heat_client = self.app.client_manager.orchestration
|
||||
return _show_resourcetype(heat_client, parsed_args)
|
||||
|
||||
@ -63,7 +73,8 @@ def _show_resourcetype(heat_client, parsed_args):
|
||||
'template_type': template_type}
|
||||
data = heat_client.resource_types.generate_template(**fields)
|
||||
else:
|
||||
data = heat_client.resource_types.get(parsed_args.resource_type)
|
||||
data = heat_client.resource_types.get(parsed_args.resource_type,
|
||||
parsed_args.long)
|
||||
except heat_exc.HTTPNotFound:
|
||||
raise exc.CommandError(
|
||||
_('Resource type not found: %s') % parsed_args.resource_type)
|
||||
|
@ -38,7 +38,7 @@ class TestResourceTypeShow(TestResourceType):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.mock_client.resource_types.get.assert_called_once_with(
|
||||
'OS::Heat::None')
|
||||
'OS::Heat::None', False)
|
||||
|
||||
def test_resourcetype_show_json(self):
|
||||
arglist = ['OS::Heat::None',
|
||||
@ -46,7 +46,7 @@ class TestResourceTypeShow(TestResourceType):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.mock_client.resource_types.get.assert_called_once_with(
|
||||
'OS::Heat::None')
|
||||
'OS::Heat::None', False)
|
||||
|
||||
def test_resourcetype_show_error_get(self):
|
||||
arglist = ['OS::Heat::None']
|
||||
@ -96,6 +96,20 @@ class TestResourceTypeShow(TestResourceType):
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
||||
def test_resourcetype_show_with_description(self):
|
||||
arglist = ['OS::Heat::None', '--long']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.mock_client.resource_types.get.assert_called_with(
|
||||
'OS::Heat::None', True)
|
||||
|
||||
def test_resourcetype_show_long_and_template_type_error(self):
|
||||
arglist = ['OS::Heat::None',
|
||||
'--template-type', 'cfn',
|
||||
'--long']
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
||||
|
||||
class TestTypeList(TestResourceType):
|
||||
|
||||
|
@ -62,15 +62,17 @@ class ResourceTypeManager(base.BaseManager):
|
||||
|
||||
return self._list(url, self.KEY)
|
||||
|
||||
def get(self, resource_type):
|
||||
def get(self, resource_type, with_description=False):
|
||||
"""Get the details for a specific resource_type.
|
||||
|
||||
:param resource_type: name of the resource type to get the details for
|
||||
:param with_description: return result with description or not
|
||||
"""
|
||||
url_str = '/%s/%s' % (
|
||||
self.KEY,
|
||||
parse.quote(encodeutils.safe_encode(resource_type), ''))
|
||||
resp = self.client.get(url_str)
|
||||
resp = self.client.get(url_str,
|
||||
params={'with_description': with_description})
|
||||
body = utils.get_response_body(resp)
|
||||
return body
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user