summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-19 04:57:30 +0000
committerGerrit Code Review <review@openstack.org>2017-06-19 04:57:30 +0000
commit7698eb05019aea0aee279aff8361ec5925203410 (patch)
treebc5e677193d063d8c517170cb98d3390e705f6f9
parent41b8e44d1e89440dca994bb927ecb35784d94e34 (diff)
parent7221cd2eba592cdb2097b3af52f9c297a54aae60 (diff)
Merge "Load all templates for generating parameter schema"
-rw-r--r--heat/engine/service.py8
-rw-r--r--heat/engine/template.py16
-rw-r--r--heat/tests/test_validate.py21
3 files changed, 41 insertions, 4 deletions
diff --git a/heat/engine/service.py b/heat/engine/service.py
index a2d5a76..a2fc9d6 100644
--- a/heat/engine/service.py
+++ b/heat/engine/service.py
@@ -696,7 +696,7 @@ class EngineService(service.ServiceBase):
696 else: 696 else:
697 tmpl = templatem.Template(template, files=files) 697 tmpl = templatem.Template(template, files=files)
698 env_util.merge_environments(environment_files, files, params, 698 env_util.merge_environments(environment_files, files, params,
699 tmpl.param_schemata()) 699 tmpl.all_param_schemata(files))
700 tmpl.env = environment.Environment(params) 700 tmpl.env = environment.Environment(params)
701 self._validate_new_stack(cnxt, stack_name, tmpl) 701 self._validate_new_stack(cnxt, stack_name, tmpl)
702 702
@@ -891,7 +891,7 @@ class EngineService(service.ServiceBase):
891 new_files.update(files or {}) 891 new_files.update(files or {})
892 tmpl = templatem.Template(new_template, files=new_files) 892 tmpl = templatem.Template(new_template, files=new_files)
893 env_util.merge_environments(environment_files, files, params, 893 env_util.merge_environments(environment_files, files, params,
894 tmpl.param_schemata()) 894 tmpl.all_param_schemata(files))
895 existing_env = current_stack.env.env_as_dict() 895 existing_env = current_stack.env.env_as_dict()
896 existing_params = existing_env[env_fmt.PARAMETERS] 896 existing_params = existing_env[env_fmt.PARAMETERS]
897 clear_params = set(args.get(rpc_api.PARAM_CLEAR_PARAMETERS, [])) 897 clear_params = set(args.get(rpc_api.PARAM_CLEAR_PARAMETERS, []))
@@ -912,7 +912,7 @@ class EngineService(service.ServiceBase):
912 else: 912 else:
913 tmpl = templatem.Template(template, files=files) 913 tmpl = templatem.Template(template, files=files)
914 env_util.merge_environments(environment_files, files, params, 914 env_util.merge_environments(environment_files, files, params,
915 tmpl.param_schemata()) 915 tmpl.all_param_schemata(files))
916 tmpl.env = environment.Environment(params) 916 tmpl.env = environment.Environment(params)
917 917
918 max_resources = cfg.CONF.max_resources_per_stack 918 max_resources = cfg.CONF.max_resources_per_stack
@@ -1221,7 +1221,7 @@ class EngineService(service.ServiceBase):
1221 1221
1222 tmpl = templatem.Template(template, files=files) 1222 tmpl = templatem.Template(template, files=files)
1223 env_util.merge_environments(environment_files, files, params, 1223 env_util.merge_environments(environment_files, files, params,
1224 tmpl.param_schemata()) 1224 tmpl.all_param_schemata(files))
1225 tmpl.env = environment.Environment(params) 1225 tmpl.env = environment.Environment(params)
1226 try: 1226 try:
1227 self._validate_template(cnxt, tmpl) 1227 self._validate_template(cnxt, tmpl)
diff --git a/heat/engine/template.py b/heat/engine/template.py
index 5aa6c51..92f395e 100644
--- a/heat/engine/template.py
+++ b/heat/engine/template.py
@@ -22,6 +22,7 @@ from stevedore import extension
22 22
23from heat.common import exception 23from heat.common import exception
24from heat.common.i18n import _ 24from heat.common.i18n import _
25from heat.common import template_format
25from heat.engine import conditions 26from heat.engine import conditions
26from heat.engine import environment 27from heat.engine import environment
27from heat.engine import function 28from heat.engine import function
@@ -195,6 +196,21 @@ class Template(collections.Mapping):
195 """Return a dict of parameters.Schema objects for the parameters.""" 196 """Return a dict of parameters.Schema objects for the parameters."""
196 pass 197 pass
197 198
199 def all_param_schemata(self, files):
200 schema = {}
201 files = files if files is not None else {}
202 for f in files.values():
203 try:
204 data = template_format.parse(f)
205 except ValueError:
206 continue
207 else:
208 sub_tmpl = Template(data)
209 schema.update(sub_tmpl.param_schemata())
210 # Parent template has precedence, so update the schema last.
211 schema.update(self.param_schemata())
212 return schema
213
198 @abc.abstractmethod 214 @abc.abstractmethod
199 def get_section_name(self, section): 215 def get_section_name(self, section):
200 """Return a correct section name.""" 216 """Return a correct section name."""
diff --git a/heat/tests/test_validate.py b/heat/tests/test_validate.py
index 4664717..234dcd3 100644
--- a/heat/tests/test_validate.py
+++ b/heat/tests/test_validate.py
@@ -1011,6 +1011,27 @@ class ValidateTest(common.HeatTestCase):
1011 res['Parameters']['net_name']['Value']) 1011 res['Parameters']['net_name']['Value'])
1012 self.assertNotIn('Default', res['Parameters']['net_name']) 1012 self.assertNotIn('Default', res['Parameters']['net_name'])
1013 1013
1014 def test_validate_parameters_nested(self):
1015 t = template_format.parse(test_template_allowed_integers)
1016
1017 other_template = test_template_no_default.replace(
1018 'net_name', 'net_name2')
1019
1020 files = {'env1': 'parameter_defaults:\n net_name: net1',
1021 'env2': 'parameter_defaults:'
1022 '\n net_name: net2'
1023 '\n net_name2: net3',
1024 'tmpl1.yaml': test_template_no_default,
1025 'tmpl2.yaml': other_template}
1026 params = {'parameters': {}, 'parameter_defaults': {}}
1027
1028 self.engine.validate_template(
1029 self.ctx, t,
1030 params=params,
1031 files=files, environment_files=['env1', 'env2'])
1032 self.assertEqual('net2', params['parameter_defaults']['net_name'])
1033 self.assertEqual('net3', params['parameter_defaults']['net_name2'])
1034
1014 def test_validate_hot_empty_parameters_valid(self): 1035 def test_validate_hot_empty_parameters_valid(self):
1015 t = template_format.parse( 1036 t = template_format.parse(
1016 """ 1037 """