Return condition functions based on the filter param
Add 'with_condition_func' filter param for API template-function-list, if the param set to true, the response will include the condition functions. Change-Id: Ia7b4da71ed5c3da105dd23917e4921a96e445026 Closes-Bug: #1625505
This commit is contained in:
parent
c14e1827f6
commit
0ac4a80dad
|
@ -57,6 +57,12 @@ class FunctionList(command.Lister):
|
||||||
metavar='<template-version>',
|
metavar='<template-version>',
|
||||||
help=_('Template version to get the functions for')
|
help=_('Template version to get the functions for')
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--with_conditions',
|
||||||
|
default=False,
|
||||||
|
action='store_true',
|
||||||
|
help=_('Show condition functions for template.')
|
||||||
|
)
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
@ -67,7 +73,8 @@ class FunctionList(command.Lister):
|
||||||
|
|
||||||
version = parsed_args.template_version
|
version = parsed_args.template_version
|
||||||
try:
|
try:
|
||||||
functions = client.template_versions.get(version)
|
functions = client.template_versions.get(
|
||||||
|
version, with_condition_func=parsed_args.with_conditions)
|
||||||
except exc.HTTPNotFound:
|
except exc.HTTPNotFound:
|
||||||
msg = _('Template version not found: %s') % version
|
msg = _('Template version not found: %s') % version
|
||||||
raise exc.CommandError(msg)
|
raise exc.CommandError(msg)
|
||||||
|
|
|
@ -54,26 +54,42 @@ class TestTemplateFunctionList(TestTemplate):
|
||||||
|
|
||||||
defaults = [
|
defaults = [
|
||||||
{'functions': 'func1', 'description': 'Function 1'},
|
{'functions': 'func1', 'description': 'Function 1'},
|
||||||
{'functions': 'func2', 'description': 'Function 2'}
|
{'functions': 'func2', 'description': 'Function 2'},
|
||||||
|
{'functions': 'condition func', 'description': 'Condition Function'}
|
||||||
]
|
]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestTemplateFunctionList, self).setUp()
|
super(TestTemplateFunctionList, self).setUp()
|
||||||
tv1 = template_versions.TemplateVersion(None, self.defaults[0])
|
self.tv1 = template_versions.TemplateVersion(None, self.defaults[0])
|
||||||
tv2 = template_versions.TemplateVersion(None, self.defaults[1])
|
self.tv2 = template_versions.TemplateVersion(None, self.defaults[1])
|
||||||
self.template_versions.get.return_value = [tv1, tv2]
|
self.tv_with_cf = template_versions.TemplateVersion(
|
||||||
|
None, self.defaults[2])
|
||||||
|
|
||||||
self.cmd = template.FunctionList(self.app, None)
|
self.cmd = template.FunctionList(self.app, None)
|
||||||
|
|
||||||
def test_function_list(self):
|
def test_function_list(self):
|
||||||
arglist = ['version1']
|
arglist = ['version1']
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||||
|
self.template_versions.get.return_value = [self.tv1, self.tv2]
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.assertEqual(['functions', 'description'], columns)
|
self.assertEqual(['functions', 'description'], columns)
|
||||||
self.assertEqual([('func1', 'Function 1'), ('func2', 'Function 2')],
|
self.assertEqual([('func1', 'Function 1'), ('func2', 'Function 2')],
|
||||||
list(data))
|
list(data))
|
||||||
|
|
||||||
|
def test_function_list_with_condition_func(self):
|
||||||
|
arglist = ['version1', '--with_conditions']
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||||
|
self.template_versions.get.return_value = [self.tv1, self.tv2,
|
||||||
|
self.tv_with_cf]
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.assertEqual(['functions', 'description'], columns)
|
||||||
|
self.assertEqual([('func1', 'Function 1'),
|
||||||
|
('func2', 'Function 2'),
|
||||||
|
('condition func', 'Condition Function')],
|
||||||
|
list(data))
|
||||||
|
|
||||||
def test_function_list_not_found(self):
|
def test_function_list_not_found(self):
|
||||||
arglist = ['bad_version']
|
arglist = ['bad_version']
|
||||||
self.template_versions.get.side_effect = exc.HTTPNotFound
|
self.template_versions.get.side_effect = exc.HTTPNotFound
|
||||||
|
|
|
@ -35,11 +35,19 @@ class TemplateVersionManager(base.BaseManager):
|
||||||
"""
|
"""
|
||||||
return self._list('/template_versions', 'template_versions')
|
return self._list('/template_versions', 'template_versions')
|
||||||
|
|
||||||
def get(self, template_version):
|
def get(self, template_version, **kwargs):
|
||||||
"""Get a list of functions for a specific resource_type.
|
"""Get a list of functions for a specific resource_type.
|
||||||
|
|
||||||
:param template_version: template version to get the functions for
|
:param template_version: template version to get the functions for
|
||||||
"""
|
"""
|
||||||
url_str = '/template_versions/%s/functions' % (
|
url_str = '/template_versions/%s/functions' % (
|
||||||
parse.quote(encodeutils.safe_encode(template_version), ''))
|
parse.quote(encodeutils.safe_encode(template_version), ''))
|
||||||
|
|
||||||
|
params = {}
|
||||||
|
if 'with_condition_func' in kwargs:
|
||||||
|
with_condition_func = kwargs.pop('with_condition_func')
|
||||||
|
params.update({'with_condition_func': with_condition_func})
|
||||||
|
if params:
|
||||||
|
url_str += '?%s' % parse.urlencode(params, True)
|
||||||
|
|
||||||
return self._list(url_str, 'template_functions')
|
return self._list(url_str, 'template_functions')
|
||||||
|
|
Loading…
Reference in New Issue