blob: 00000fd90563f6ccac59a4638b35fdb685685500 [file] [log] [blame]
Angus Salkeld95f65a22014-11-24 12:38:30 +10001# 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
13import yaml
14
15from heat_integrationtests.common import test
16
17
18class DefaultParametersTest(test.HeatIntegrationTest):
19
20 template = '''
21heat_template_version: 2013-05-23
22parameters:
23 length:
24 type: string
25 default: 40
26resources:
27 random1:
28 type: nested_random.yaml
29 random2:
30 type: OS::Heat::RandomString
31 properties:
32 length: {get_param: length}
33outputs:
34 random1:
35 value: {get_attr: [random1, random1_value]}
36 random2:
37 value: {get_resource: random2}
38'''
39 nested_template = '''
40heat_template_version: 2013-05-23
41parameters:
42 length:
43 type: string
44 default: 50
45resources:
46 random1:
47 type: OS::Heat::RandomString
48 properties:
49 length: {get_param: length}
50outputs:
51 random1_value:
52 value: {get_resource: random1}
53'''
54
55 scenarios = [
56 ('none', dict(param=None, default=None, temp_def=True,
57 expect1=50, expect2=40)),
58 ('default', dict(param=None, default=12, temp_def=True,
59 expect1=12, expect2=12)),
60 ('both', dict(param=15, default=12, temp_def=True,
61 expect1=12, expect2=15)),
62 ('no_temp_default', dict(param=None, default=12, temp_def=False,
63 expect1=12, expect2=12)),
64 ]
65
66 def setUp(self):
67 super(DefaultParametersTest, self).setUp()
68 self.client = self.orchestration_client
69
70 def test_defaults(self):
Angus Salkeld95f65a22014-11-24 12:38:30 +100071 env = {'parameters': {}, 'parameter_defaults': {}}
72 if self.param:
73 env['parameters'] = {'length': self.param}
74 if self.default:
75 env['parameter_defaults'] = {'length': self.default}
76
77 if not self.temp_def:
78 # remove the default from the parameter in the nested template.
79 ntempl = yaml.load(self.nested_template)
80 del ntempl['parameters']['length']['default']
81 nested_template = yaml.dump(ntempl)
82 else:
83 nested_template = self.nested_template
84
Sergey Kraynevbf67ce32015-04-17 10:54:20 -040085 stack_identifier = self.stack_create(
Angus Salkeld95f65a22014-11-24 12:38:30 +100086 template=self.template,
87 files={'nested_random.yaml': nested_template},
Angus Salkeld95f65a22014-11-24 12:38:30 +100088 environment=env
89 )
Angus Salkeld95f65a22014-11-24 12:38:30 +100090
Sergey Kraynevbf67ce32015-04-17 10:54:20 -040091 stack = self.client.stacks.get(stack_identifier)
Angus Salkeld95f65a22014-11-24 12:38:30 +100092 for out in stack.outputs:
93 if out['output_key'] == 'random1':
94 self.assertEqual(self.expect1, len(out['output_value']))
95 if out['output_key'] == 'random2':
96 self.assertEqual(self.expect2, len(out['output_value']))