Merge "Return condition functions based on the filter param"
This commit is contained in:
commit
c2d6de9a98
heatclient
@ -57,6 +57,12 @@ class FunctionList(command.Lister):
|
||||
metavar='<template-version>',
|
||||
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
|
||||
|
||||
@ -67,7 +73,8 @@ class FunctionList(command.Lister):
|
||||
|
||||
version = parsed_args.template_version
|
||||
try:
|
||||
functions = client.template_versions.get(version)
|
||||
functions = client.template_versions.get(
|
||||
version, with_condition_func=parsed_args.with_conditions)
|
||||
except exc.HTTPNotFound:
|
||||
msg = _('Template version not found: %s') % version
|
||||
raise exc.CommandError(msg)
|
||||
|
@ -54,26 +54,42 @@ class TestTemplateFunctionList(TestTemplate):
|
||||
|
||||
defaults = [
|
||||
{'functions': 'func1', 'description': 'Function 1'},
|
||||
{'functions': 'func2', 'description': 'Function 2'}
|
||||
{'functions': 'func2', 'description': 'Function 2'},
|
||||
{'functions': 'condition func', 'description': 'Condition Function'}
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
super(TestTemplateFunctionList, self).setUp()
|
||||
tv1 = template_versions.TemplateVersion(None, self.defaults[0])
|
||||
tv2 = template_versions.TemplateVersion(None, self.defaults[1])
|
||||
self.template_versions.get.return_value = [tv1, tv2]
|
||||
self.tv1 = template_versions.TemplateVersion(None, self.defaults[0])
|
||||
self.tv2 = template_versions.TemplateVersion(None, self.defaults[1])
|
||||
self.tv_with_cf = template_versions.TemplateVersion(
|
||||
None, self.defaults[2])
|
||||
|
||||
self.cmd = template.FunctionList(self.app, None)
|
||||
|
||||
def test_function_list(self):
|
||||
arglist = ['version1']
|
||||
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)
|
||||
|
||||
self.assertEqual(['functions', 'description'], columns)
|
||||
self.assertEqual([('func1', 'Function 1'), ('func2', 'Function 2')],
|
||||
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):
|
||||
arglist = ['bad_version']
|
||||
self.template_versions.get.side_effect = exc.HTTPNotFound
|
||||
|
@ -35,11 +35,19 @@ class TemplateVersionManager(base.BaseManager):
|
||||
"""
|
||||
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.
|
||||
|
||||
:param template_version: template version to get the functions for
|
||||
"""
|
||||
url_str = '/template_versions/%s/functions' % (
|
||||
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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user