Steven Hardy | 7419382 | 2015-09-15 09:38:26 +0100 | [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 | |
| 14 | import six |
| 15 | |
| 16 | from heatclient import exc |
| 17 | |
| 18 | from heat_integrationtests.functional import functional_base |
| 19 | |
| 20 | |
| 21 | class StackTemplateValidateTest(functional_base.FunctionalTestsBase): |
| 22 | |
| 23 | random_template = ''' |
| 24 | heat_template_version: 2014-10-16 |
| 25 | description: the stack description |
| 26 | parameters: |
| 27 | aparam: |
| 28 | type: number |
| 29 | default: 10 |
| 30 | description: the param description |
| 31 | resources: |
| 32 | myres: |
| 33 | type: OS::Heat::RandomString |
| 34 | properties: |
| 35 | length: {get_param: aparam} |
| 36 | ''' |
| 37 | |
| 38 | random_template_groups = ''' |
| 39 | heat_template_version: 2014-10-16 |
| 40 | description: the stack description |
| 41 | parameters: |
| 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 |
| 53 | parameter_groups: |
| 54 | - label: str_params |
| 55 | description: The string params |
| 56 | parameters: |
| 57 | - bparam |
| 58 | - cparam |
| 59 | resources: |
| 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 Hardy | 1c8499d | 2015-09-18 15:49:12 +0100 | [diff] [blame^] | 77 | 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 Hardy | 7419382 | 2015-09-15 09:38:26 +0100 | [diff] [blame] | 91 | 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) |