[VVP] revert nested resource section
[vvp/validation-scripts.git] / ice_validator / tests / test_heat_template_structure.py
1 # -*- coding: utf8 -*-
2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
7 #
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
12 #
13 #             http://www.apache.org/licenses/LICENSE-2.0
14 #
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.
20 #
21 #
22 #
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
27 #
28 #             https://creativecommons.org/licenses/by/4.0/
29 #
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.
35 #
36 # ============LICENSE_END============================================
37 #
38 #
39
40 """Test heat template structure
41 """
42
43 from tests import cached_yaml as yaml
44 from .helpers import validates
45
46 VERSION = "1.2.0"
47
48 # pylint: disable=invalid-name
49
50
51 @validates("R-27078")
52 def test_heat_template_structure_contains_heat_template_version(yaml_file):
53     """
54     Check that all heat templates have the required sections
55     """
56     required_key_values = ["heat_template_version"]
57
58     with open(yaml_file) as fh:
59         yml = yaml.load(fh)
60     assert all(
61         [k in yml for k in required_key_values]
62     ), "{} doesn't contain the {} section, but it is required".format(
63         yaml_file, required_key_values[0]
64     )
65
66
67 @validates("R-39402")
68 def test_heat_template_structure_contains_description(yaml_file):
69     """
70     Check that all heat templates have the required sections
71     """
72     required_key_values = ["description"]
73
74     with open(yaml_file) as fh:
75         yml = yaml.load(fh)
76     assert all(
77         [k in yml for k in required_key_values]
78     ), "{} doesn't contain the {} section, but it is required".format(
79         yaml_file, required_key_values[0]
80     )
81
82
83 @validates("R-35414")
84 def test_heat_template_structure_contains_parameters(yaml_file):
85     """
86     Check that all heat templates have the required sections
87     """
88     required_key_values = ["parameters"]
89
90     with open(yaml_file) as fh:
91         yml = yaml.load(fh)
92     assert all(
93         [k in yml for k in required_key_values]
94     ), "{} doesn't contain the {} section, but it is required".format(
95         yaml_file, required_key_values[0]
96     )
97
98
99 @validates("R-23664")
100 def test_heat_template_structure_contains_resources(heat_template):
101     """
102     Check that all heat templates have the required sections
103     """
104     required_key_values = ["resources"]
105
106     with open(heat_template) as fh:
107         yml = yaml.load(fh)
108     assert all(
109         [k in yml for k in required_key_values]
110     ), "{} doesn't contain the {} section, but it is required".format(
111         heat_template, required_key_values[0]
112     )
113
114
115 @validates("R-11441")
116 def test_parameter_type(yaml_file):
117     """A VNF's Heat Orchestration Template's parameter type **MUST**
118     be one of the following values:
119     """
120     types = ["string", "number", "json", "comma_delimited_list", "boolean"]
121     with open(yaml_file) as fh:
122         yml = yaml.load(fh)
123     for key, param in yml.get("parameters", {}).items():
124         assert isinstance(param, dict), "%s parameter %s is not dict" % (yaml_file, key)
125         if "type" not in param:
126             continue
127         typ = param["type"]
128         assert typ in types, '%s parameter %s has invalid type "%s"' % (
129             yaml_file,
130             key,
131             typ,
132         )