Angus Salkeld | 95f65a2 | 2014-11-24 12:38:30 +1000 | [diff] [blame] | 1 | # 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 | import yaml |
| 14 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 15 | from heat_integrationtests.functional import functional_base |
Angus Salkeld | 95f65a2 | 2014-11-24 12:38:30 +1000 | [diff] [blame] | 16 | |
| 17 | |
Rabi Mishra | 477efc9 | 2015-07-31 13:01:45 +0530 | [diff] [blame] | 18 | class DefaultParametersTest(functional_base.FunctionalTestsBase): |
Angus Salkeld | 95f65a2 | 2014-11-24 12:38:30 +1000 | [diff] [blame] | 19 | |
| 20 | template = ''' |
| 21 | heat_template_version: 2013-05-23 |
| 22 | parameters: |
| 23 | length: |
| 24 | type: string |
| 25 | default: 40 |
| 26 | resources: |
| 27 | random1: |
| 28 | type: nested_random.yaml |
| 29 | random2: |
| 30 | type: OS::Heat::RandomString |
| 31 | properties: |
| 32 | length: {get_param: length} |
| 33 | outputs: |
| 34 | random1: |
| 35 | value: {get_attr: [random1, random1_value]} |
| 36 | random2: |
| 37 | value: {get_resource: random2} |
| 38 | ''' |
| 39 | nested_template = ''' |
| 40 | heat_template_version: 2013-05-23 |
| 41 | parameters: |
| 42 | length: |
| 43 | type: string |
| 44 | default: 50 |
| 45 | resources: |
| 46 | random1: |
| 47 | type: OS::Heat::RandomString |
| 48 | properties: |
| 49 | length: {get_param: length} |
| 50 | outputs: |
| 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 Salkeld | 95f65a2 | 2014-11-24 12:38:30 +1000 | [diff] [blame] | 68 | |
| 69 | def test_defaults(self): |
Angus Salkeld | 95f65a2 | 2014-11-24 12:38:30 +1000 | [diff] [blame] | 70 | 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 Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 84 | stack_identifier = self.stack_create( |
Angus Salkeld | 95f65a2 | 2014-11-24 12:38:30 +1000 | [diff] [blame] | 85 | template=self.template, |
| 86 | files={'nested_random.yaml': nested_template}, |
Angus Salkeld | 95f65a2 | 2014-11-24 12:38:30 +1000 | [diff] [blame] | 87 | environment=env |
| 88 | ) |
Angus Salkeld | 95f65a2 | 2014-11-24 12:38:30 +1000 | [diff] [blame] | 89 | |
Sergey Kraynev | bf67ce3 | 2015-04-17 10:54:20 -0400 | [diff] [blame] | 90 | stack = self.client.stacks.get(stack_identifier) |
Angus Salkeld | 95f65a2 | 2014-11-24 12:38:30 +1000 | [diff] [blame] | 91 | 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'])) |