From 0ac4a80dada9a7fb9ee13d965c496b2b7341a4d5 Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Tue, 18 Oct 2016 10:32:01 +0800 Subject: [PATCH] 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 --- heatclient/osc/v1/template.py | 9 ++++++- heatclient/tests/unit/osc/v1/test_template.py | 26 +++++++++++++++---- heatclient/v1/template_versions.py | 10 ++++++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/heatclient/osc/v1/template.py b/heatclient/osc/v1/template.py index 1b089dd7..c4ed1249 100644 --- a/heatclient/osc/v1/template.py +++ b/heatclient/osc/v1/template.py @@ -57,6 +57,12 @@ class FunctionList(command.Lister): metavar='', 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) diff --git a/heatclient/tests/unit/osc/v1/test_template.py b/heatclient/tests/unit/osc/v1/test_template.py index 895f6285..13c6a65f 100644 --- a/heatclient/tests/unit/osc/v1/test_template.py +++ b/heatclient/tests/unit/osc/v1/test_template.py @@ -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 diff --git a/heatclient/v1/template_versions.py b/heatclient/v1/template_versions.py index 0bfc0a1d..325cc96a 100644 --- a/heatclient/v1/template_versions.py +++ b/heatclient/v1/template_versions.py @@ -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')