blob: 91e3e6a980f8382e8c5cfd973633a0a2b83d1d8c [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
Steven Hardy1c8499d2015-09-18 15:49:12 +010077 def test_template_validate_override_default(self):
78 env = {'parameters': {'aparam': 5}}
79 ret = self.client.stacks.validate(template=self.random_template,
80 environment=env)
81 expected = {'Description': 'the stack description',
82 'Parameters': {
83 'aparam': {'Default': 10,
84 'Value': 5,
85 'Description': 'the param description',
86 'Label': 'aparam',
87 'NoEcho': 'false',
88 'Type': 'Number'}}}
89 self.assertEqual(expected, ret)
90
Steven Hardy74193822015-09-15 09:38:26 +010091 def test_template_validate_basic_required_param(self):
92 tmpl = self.random_template.replace('default: 10', '')
93 ret = self.client.stacks.validate(template=tmpl)
94 expected = {'Description': 'the stack description',
95 'Parameters': {
96 'aparam': {'Description': 'the param description',
97 'Label': 'aparam',
98 'NoEcho': 'false',
99 'Type': 'Number'}}}
100 self.assertEqual(expected, ret)
101
102 def test_template_validate_fail_version(self):
103 fail_template = self.random_template.replace('2014-10-16', 'invalid')
104 ex = self.assertRaises(exc.HTTPBadRequest,
105 self.client.stacks.validate,
106 template=fail_template)
107 self.assertIn('The template version is invalid', six.text_type(ex))
108
109 def test_template_validate_parameter_groups(self):
110 ret = self.client.stacks.validate(template=self.random_template_groups)
111 expected = {'Description': 'the stack description',
112 'ParameterGroups':
113 [{'description': 'The string params',
114 'label': 'str_params',
115 'parameters': ['bparam', 'cparam']}],
116 'Parameters':
117 {'aparam':
118 {'Default': 10,
119 'Description': 'the param description',
120 'Label': 'aparam',
121 'NoEcho': 'false',
122 'Type': 'Number'},
123 'bparam':
124 {'Default': 'foo',
125 'Description': '',
126 'Label': 'bparam',
127 'NoEcho': 'false',
128 'Type': 'String'},
129 'cparam':
130 {'Default': 'secret',
131 'Description': '',
132 'Label': 'cparam',
133 'NoEcho': 'true',
134 'Type': 'String'}}}
135 self.assertEqual(expected, ret)