blob: 3e00c35ac81679c54d6c28c231e30d962ca83bcb [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
Rabi Mishra477efc92015-07-31 13:01:45 +053015from heat_integrationtests.functional import functional_base
Angus Salkeld95f65a22014-11-24 12:38:30 +100016
17
Rabi Mishra477efc92015-07-31 13:01:45 +053018class DefaultParametersTest(functional_base.FunctionalTestsBase):
Angus Salkeld95f65a22014-11-24 12:38:30 +100019
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()
Angus Salkeld95f65a22014-11-24 12:38:30 +100068
69 def test_defaults(self):
Angus Salkeld95f65a22014-11-24 12:38:30 +100070 env = {'parameters': {}, 'parameter_defaults': {}}
71 if self.param:
72 env['parameters'] = {'length': self.param}
73 if self.default:
74 env['parameter_defaults'] = {'length': self.default}
75
76 if not self.temp_def:
77 # remove the default from the parameter in the nested template.
78 ntempl = yaml.load(self.nested_template)
79 del ntempl['parameters']['length']['default']
80 nested_template = yaml.dump(ntempl)
81 else:
82 nested_template = self.nested_template
83
Sergey Kraynevbf67ce32015-04-17 10:54:20 -040084 stack_identifier = self.stack_create(
Angus Salkeld95f65a22014-11-24 12:38:30 +100085 template=self.template,
86 files={'nested_random.yaml': nested_template},
Angus Salkeld95f65a22014-11-24 12:38:30 +100087 environment=env
88 )
Angus Salkeld95f65a22014-11-24 12:38:30 +100089
Sergey Kraynevbf67ce32015-04-17 10:54:20 -040090 stack = self.client.stacks.get(stack_identifier)
Angus Salkeld95f65a22014-11-24 12:38:30 +100091 for out in stack.outputs:
92 if out['output_key'] == 'random1':
93 self.assertEqual(self.expect1, len(out['output_value']))
94 if out['output_key'] == 'random2':
95 self.assertEqual(self.expect2, len(out['output_value']))