2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
8 # Unless otherwise specified, all software contained herein is licensed
9 # under the Apache License, Version 2.0 (the "License");
10 # you may not use this software except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
23 # Unless otherwise specified, all documentation contained herein is licensed
24 # under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 # you may not use this documentation except in compliance with the License.
26 # You may obtain a copy of the License at
28 # https://creativecommons.org/licenses/by/4.0/
30 # Unless required by applicable law or agreed to in writing, documentation
31 # distributed under the License is distributed on an "AS IS" BASIS,
32 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 # See the License for the specific language governing permissions and
34 # limitations under the License.
36 # ============LICENSE_END============================================
38 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
41 """Test heat template structure
44 from tests import cached_yaml as yaml
45 from .helpers import validates
49 # pylint: disable=invalid-name
53 def test_heat_template_structure_contains_heat_template_version(yaml_file):
55 Check that all heat templates have the required sections
57 required_key_values = ["heat_template_version"]
59 with open(yaml_file) as fh:
62 [k in yml for k in required_key_values]
63 ), "{} doesn't contain the {} section, but it is required".format(
64 yaml_file, required_key_values[0]
69 def test_heat_template_structure_contains_description(yaml_file):
71 Check that all heat templates have the required sections
73 required_key_values = ["description"]
75 with open(yaml_file) as fh:
78 [k in yml for k in required_key_values]
79 ), "{} doesn't contain the {} section, but it is required".format(
80 yaml_file, required_key_values[0]
85 def test_heat_template_structure_contains_parameters(yaml_file):
87 Check that all heat templates have the required sections
89 required_key_values = ["parameters"]
91 with open(yaml_file) as fh:
94 [k in yml for k in required_key_values]
95 ), "{} doesn't contain the {} section, but it is required".format(
96 yaml_file, required_key_values[0]
100 @validates("R-23664")
101 def test_heat_template_structure_contains_resources(heat_template):
103 Check that all heat templates have the required sections
105 required_key_values = ["resources"]
107 with open(heat_template) as fh:
110 [k in yml for k in required_key_values]
111 ), "{} doesn't contain the {} section, but it is required".format(
112 heat_template, required_key_values[0]
116 @validates("R-11441")
117 def test_parameter_type(yaml_file):
118 """A VNF's Heat Orchestration Template's parameter type **MUST**
119 be one of the following values:
121 types = ["string", "number", "json", "comma_delimited_list", "boolean"]
122 with open(yaml_file) as fh:
124 for key, param in yml.get("parameters", {}).items():
125 assert isinstance(param, dict), "%s parameter %s is not dict" % (yaml_file, key)
126 if "type" not in param:
129 assert typ in types, '%s parameter %s has invalid type "%s"' % (