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: Icdfbafbb98698373648ff2d78db3c45fe2b924ee Closes-Bug: #1625505
This commit is contained in:
parent
cf988a60f2
commit
62f6045f2a
@ -653,10 +653,18 @@ class StackController(object):
|
|||||||
@util.policy_enforce
|
@util.policy_enforce
|
||||||
def list_template_functions(self, req, template_version):
|
def list_template_functions(self, req, template_version):
|
||||||
"""Returns a list of available functions in a given template."""
|
"""Returns a list of available functions in a given template."""
|
||||||
|
if req.params.get('with_condition_func') is not None:
|
||||||
|
with_condition = self._extract_bool_param(
|
||||||
|
'with_condition_func',
|
||||||
|
req.params.get('with_condition_func'))
|
||||||
|
else:
|
||||||
|
with_condition = False
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'template_functions':
|
'template_functions':
|
||||||
self.rpc_client.list_template_functions(req.context,
|
self.rpc_client.list_template_functions(req.context,
|
||||||
template_version)
|
template_version,
|
||||||
|
with_condition)
|
||||||
}
|
}
|
||||||
|
|
||||||
@util.policy_enforce
|
@util.policy_enforce
|
||||||
|
@ -303,7 +303,7 @@ class EngineService(service.Service):
|
|||||||
by the RPC caller.
|
by the RPC caller.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
RPC_API_VERSION = '1.34'
|
RPC_API_VERSION = '1.35'
|
||||||
|
|
||||||
def __init__(self, host, topic):
|
def __init__(self, host, topic):
|
||||||
super(EngineService, self).__init__()
|
super(EngineService, self).__init__()
|
||||||
@ -1562,7 +1562,8 @@ class EngineService(service.Service):
|
|||||||
|
|
||||||
return versions
|
return versions
|
||||||
|
|
||||||
def list_template_functions(self, cnxt, template_version):
|
def list_template_functions(self, cnxt, template_version,
|
||||||
|
with_condition=False):
|
||||||
mgr = templatem._get_template_extension_manager()
|
mgr = templatem._get_template_extension_manager()
|
||||||
try:
|
try:
|
||||||
tmpl_class = mgr[template_version]
|
tmpl_class = mgr[template_version]
|
||||||
@ -1570,8 +1571,12 @@ class EngineService(service.Service):
|
|||||||
raise exception.NotFound(_("Template with version %s not found") %
|
raise exception.NotFound(_("Template with version %s not found") %
|
||||||
template_version)
|
template_version)
|
||||||
|
|
||||||
|
supported_funcs = tmpl_class.plugin.functions
|
||||||
|
if with_condition:
|
||||||
|
supported_funcs.update(tmpl_class.plugin.condition_functions)
|
||||||
|
|
||||||
functions = []
|
functions = []
|
||||||
for func_name, func in six.iteritems(tmpl_class.plugin.functions):
|
for func_name, func in six.iteritems(supported_funcs):
|
||||||
if func is not hot_functions.Removed:
|
if func is not hot_functions.Removed:
|
||||||
if func.__doc__.split('\n')[0]:
|
if func.__doc__.split('\n')[0]:
|
||||||
desc = func.__doc__.split('\n')[0].strip()
|
desc = func.__doc__.split('\n')[0].strip()
|
||||||
|
@ -57,6 +57,7 @@ class EngineClient(object):
|
|||||||
1.33 - Remove tenant_safe from list_stacks, count_stacks
|
1.33 - Remove tenant_safe from list_stacks, count_stacks
|
||||||
and list_software_configs
|
and list_software_configs
|
||||||
1.34 - Add migrate_convergence_1 call
|
1.34 - Add migrate_convergence_1 call
|
||||||
|
1.35 - Add with_condition to list_template_functions
|
||||||
"""
|
"""
|
||||||
|
|
||||||
BASE_RPC_API_VERSION = '1.0'
|
BASE_RPC_API_VERSION = '1.0'
|
||||||
@ -473,16 +474,20 @@ class EngineClient(object):
|
|||||||
return self.call(ctxt, self.make_msg('list_template_versions'),
|
return self.call(ctxt, self.make_msg('list_template_versions'),
|
||||||
version='1.11')
|
version='1.11')
|
||||||
|
|
||||||
def list_template_functions(self, ctxt, template_version):
|
def list_template_functions(self, ctxt, template_version,
|
||||||
|
with_condition=False):
|
||||||
"""Get a list of available functions in a given template.
|
"""Get a list of available functions in a given template.
|
||||||
|
|
||||||
:param ctxt: RPC context
|
:param ctxt: RPC context
|
||||||
:param template_name : name of the template which function list you
|
:param template_name : name of the template which function list you
|
||||||
want to get
|
want to get
|
||||||
|
:param with_condition: return includes condition functions.
|
||||||
"""
|
"""
|
||||||
return self.call(ctxt, self.make_msg(
|
return self.call(ctxt,
|
||||||
'list_template_functions', template_version=template_version),
|
self.make_msg('list_template_functions',
|
||||||
version='1.13')
|
template_version=template_version,
|
||||||
|
with_condition=with_condition),
|
||||||
|
version='1.35')
|
||||||
|
|
||||||
def resource_schema(self, ctxt, type_name, with_description=False):
|
def resource_schema(self, ctxt, type_name, with_description=False):
|
||||||
"""Get the schema for a resource type.
|
"""Get the schema for a resource type.
|
||||||
|
@ -2567,19 +2567,16 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
|
|||||||
self.assertEqual({'template_versions': engine_response}, response)
|
self.assertEqual({'template_versions': engine_response}, response)
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
def test_list_template_functions(self, mock_enforce):
|
def _test_list_template_functions(self, mock_enforce, req, engine_response,
|
||||||
|
with_condition=False):
|
||||||
self._mock_enforce_setup(mock_enforce, 'list_template_functions', True)
|
self._mock_enforce_setup(mock_enforce, 'list_template_functions', True)
|
||||||
req = self._get('/template_versions/t1/functions')
|
|
||||||
|
|
||||||
engine_response = [
|
|
||||||
{'functions': 'func1', 'description': 'desc1'},
|
|
||||||
]
|
|
||||||
|
|
||||||
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
|
self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
|
||||||
rpc_client.EngineClient.call(
|
rpc_client.EngineClient.call(
|
||||||
req.context, (
|
req.context, (
|
||||||
'list_template_functions', {'template_version': 't1'}),
|
'list_template_functions',
|
||||||
version="1.13"
|
{'template_version': 't1', 'with_condition': with_condition}),
|
||||||
|
version="1.35"
|
||||||
).AndReturn(engine_response)
|
).AndReturn(engine_response)
|
||||||
self.m.ReplayAll()
|
self.m.ReplayAll()
|
||||||
response = self.controller.list_template_functions(
|
response = self.controller.list_template_functions(
|
||||||
@ -2587,6 +2584,26 @@ class StackControllerTest(tools.ControllerTest, common.HeatTestCase):
|
|||||||
self.assertEqual({'template_functions': engine_response}, response)
|
self.assertEqual({'template_functions': engine_response}, response)
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
|
def test_list_template_functions(self, mock_enforce):
|
||||||
|
req = self._get('/template_versions/t1/functions')
|
||||||
|
engine_response = [
|
||||||
|
{'functions': 'func1', 'description': 'desc1'},
|
||||||
|
]
|
||||||
|
|
||||||
|
self._test_list_template_functions(mock_enforce, req, engine_response)
|
||||||
|
|
||||||
|
def test_list_template_funcs_includes_condition_funcs(self, mock_enforce):
|
||||||
|
params = {'with_condition_func': 'true'}
|
||||||
|
req = self._get('/template_versions/t1/functions', params=params)
|
||||||
|
|
||||||
|
engine_response = [
|
||||||
|
{'functions': 'func1', 'description': 'desc1'},
|
||||||
|
{'functions': 'condition_func', 'description': 'desc2'}
|
||||||
|
]
|
||||||
|
|
||||||
|
self._test_list_template_functions(mock_enforce, req, engine_response,
|
||||||
|
with_condition=True)
|
||||||
|
|
||||||
def test_resource_schema(self, mock_enforce):
|
def test_resource_schema(self, mock_enforce):
|
||||||
self._mock_enforce_setup(mock_enforce, 'resource_schema', True)
|
self._mock_enforce_setup(mock_enforce, 'resource_schema', True)
|
||||||
req = self._get('/resource_types/ResourceWithProps')
|
req = self._get('/resource_types/ResourceWithProps')
|
||||||
|
@ -40,7 +40,7 @@ class ServiceEngineTest(common.HeatTestCase):
|
|||||||
|
|
||||||
def test_make_sure_rpc_version(self):
|
def test_make_sure_rpc_version(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
'1.34',
|
'1.35',
|
||||||
service.EngineService.RPC_API_VERSION,
|
service.EngineService.RPC_API_VERSION,
|
||||||
('RPC version is changed, please update this test to new version '
|
('RPC version is changed, please update this test to new version '
|
||||||
'and make sure additional test cases are added for RPC APIs '
|
'and make sure additional test cases are added for RPC APIs '
|
||||||
|
@ -905,10 +905,17 @@ class StackServiceTest(common.HeatTestCase):
|
|||||||
Dummy Func2 Long Description.
|
Dummy Func2 Long Description.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class DummyConditionFunc(object):
|
||||||
|
"""Dummy Condition Func.
|
||||||
|
|
||||||
|
Dummy Condition Func Long Description.
|
||||||
|
"""
|
||||||
|
|
||||||
plugin_mock = mock.Mock(
|
plugin_mock = mock.Mock(
|
||||||
functions={'dummy1': DummyFunc1,
|
functions={'dummy1': DummyFunc1,
|
||||||
'dummy2': DummyFunc2,
|
'dummy2': DummyFunc2,
|
||||||
'removed': hot_functions.Removed})
|
'removed': hot_functions.Removed},
|
||||||
|
condition_functions={'condition_dummy': DummyConditionFunc})
|
||||||
dummy_tmpl = mock.Mock(plugin=plugin_mock)
|
dummy_tmpl = mock.Mock(plugin=plugin_mock)
|
||||||
|
|
||||||
class DummyMgr(object):
|
class DummyMgr(object):
|
||||||
@ -924,6 +931,18 @@ class StackServiceTest(common.HeatTestCase):
|
|||||||
self.assertEqual(sorted(expected, key=lambda k: k['functions']),
|
self.assertEqual(sorted(expected, key=lambda k: k['functions']),
|
||||||
sorted(functions, key=lambda k: k['functions']))
|
sorted(functions, key=lambda k: k['functions']))
|
||||||
|
|
||||||
|
# test with_condition
|
||||||
|
functions = self.eng.list_template_functions(self.ctx, 'dummytemplate',
|
||||||
|
with_condition=True)
|
||||||
|
expected = [{'functions': 'dummy1',
|
||||||
|
'description': 'Dummy Func1.'},
|
||||||
|
{'functions': 'dummy2',
|
||||||
|
'description': 'Dummy Func2.'},
|
||||||
|
{'functions': 'condition_dummy',
|
||||||
|
'description': 'Dummy Condition Func.'}]
|
||||||
|
self.assertEqual(sorted(expected, key=lambda k: k['functions']),
|
||||||
|
sorted(functions, key=lambda k: k['functions']))
|
||||||
|
|
||||||
@mock.patch('heat.engine.template._get_template_extension_manager')
|
@mock.patch('heat.engine.template._get_template_extension_manager')
|
||||||
def test_list_template_functions_version_not_found(self, templ_mock):
|
def test_list_template_functions_version_not_found(self, templ_mock):
|
||||||
class DummyMgr(object):
|
class DummyMgr(object):
|
||||||
|
Loading…
Reference in New Issue
Block a user