blob: 9dd0947bf2a5e94b97a2fd5fd62c3406063a98af [file] [log] [blame]
Steven Hardy74193822015-09-15 09:38:26 +01001# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13
14import six
15
16from heatclient import exc
17
18from heat_integrationtests.functional import functional_base
19
20
21class StackTemplateValidateTest(functional_base.FunctionalTestsBase):
22
23 random_template = '''
24heat_template_version: 2014-10-16
25description: the stack description
26parameters:
27 aparam:
28 type: number
29 default: 10
30 description: the param description
31resources:
32 myres:
33 type: OS::Heat::RandomString
34 properties:
35 length: {get_param: aparam}
36'''
37
38 random_template_groups = '''
39heat_template_version: 2014-10-16
40description: the stack description
41parameters:
42 aparam:
43 type: number
44 default: 10
45 description: the param description
46 bparam:
47 type: string
48 default: foo
49 cparam:
50 type: string
51 default: secret
52 hidden: true
53parameter_groups:
54- label: str_params
55 description: The string params
56 parameters:
57 - bparam
58 - cparam
59resources:
60 myres:
61 type: OS::Heat::RandomString
62 properties:
63 length: {get_param: aparam}
64'''
65
66 def test_template_validate_basic(self):
67 ret = self.client.stacks.validate(template=self.random_template)
68 expected = {'Description': 'the stack description',
69 'Parameters': {
70 'aparam': {'Default': 10,
71 'Description': 'the param description',
72 'Label': 'aparam',
73 'NoEcho': 'false',
74 'Type': 'Number'}}}
75 self.assertEqual(expected, ret)
76
77 def test_template_validate_basic_required_param(self):
78 tmpl = self.random_template.replace('default: 10', '')
79 ret = self.client.stacks.validate(template=tmpl)
80 expected = {'Description': 'the stack description',
81 'Parameters': {
82 'aparam': {'Description': 'the param description',
83 'Label': 'aparam',
84 'NoEcho': 'false',
85 'Type': 'Number'}}}
86 self.assertEqual(expected, ret)
87
88 def test_template_validate_fail_version(self):
89 fail_template = self.random_template.replace('2014-10-16', 'invalid')
90 ex = self.assertRaises(exc.HTTPBadRequest,
91 self.client.stacks.validate,
92 template=fail_template)
93 self.assertIn('The template version is invalid', six.text_type(ex))
94
95 def test_template_validate_parameter_groups(self):
96 ret = self.client.stacks.validate(template=self.random_template_groups)
97 expected = {'Description': 'the stack description',
98 'ParameterGroups':
99 [{'description': 'The string params',
100 'label': 'str_params',
101 'parameters': ['bparam', 'cparam']}],
102 'Parameters':
103 {'aparam':
104 {'Default': 10,
105 'Description': 'the param description',
106 'Label': 'aparam',
107 'NoEcho': 'false',
108 'Type': 'Number'},
109 'bparam':
110 {'Default': 'foo',
111 'Description': '',
112 'Label': 'bparam',
113 'NoEcho': 'false',
114 'Type': 'String'},
115 'cparam':
116 {'Default': 'secret',
117 'Description': '',
118 'Label': 'cparam',
119 'NoEcho': 'true',
120 'Type': 'String'}}}
121 self.assertEqual(expected, ret)