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============================================
42 from tests import cached_yaml as yaml
44 from .helpers import validates
49 def check_parameter_type(heat_template, parameter, parameter_type):
51 Make sure these OS::Nova::Server parameters are defined w/
55 with open(heat_template) as fh:
58 # skip if resources are not defined
59 if "parameters" not in yml:
60 pytest.skip("No parameters specified in the heat template")
62 invalid_parameters = []
64 for k1, v1 in yml["parameters"].items():
65 if not isinstance(v1, dict):
70 if k1.find(parameter) == -1:
73 param_type = v1.get("type")
78 if param_type != parameter_type:
79 invalid_parameters.append(k1)
82 not invalid_parameters
83 ), "{} parameters must be defined as type {}: {}".format(
84 parameter, parameter_type, invalid_parameters
88 def check_server_parameter_name(heat_template, parameter, parameter_name):
90 Check each OS::Nova::Server metadata property
91 uses the same parameter name w/ get_param
94 with open(heat_template) as fh:
97 # skip if resources are not defined
98 if "resources" not in yml:
99 pytest.skip("No resources specified in the heat template")
101 invalid_parameters = []
103 for k1, v1 in yml["resources"].items():
104 if not isinstance(v1, dict):
109 if v1["type"] != "OS::Nova::Server":
112 metadata = v1.get("properties", {}).get("metadata", {}).get(parameter)
114 if not metadata or not isinstance(metadata, dict):
117 get_param = metadata.get("get_param")
122 if get_param != parameter_name:
123 invalid_parameters.append(
126 "metadata property": parameter_name,
127 "get_param": get_param,
131 assert not invalid_parameters, (
132 "metadata property {} must use get_param and "
133 "the parameter name must be {}: {}".format(
134 parameter, parameter_name, invalid_parameters
139 @validates("R-23311")
140 def test_availability_zone_parameter_type(heat_template):
141 check_parameter_type(heat_template, "availability_zone_", "string")
144 @validates("R-07507")
145 def test_vnf_id_parameter_type_and_parameter_name(heat_template):
146 check_parameter_type(heat_template, "vnf_id", "string")
147 check_server_parameter_name(heat_template, "vnf_id", "vnf_id")
150 @validates("R-82134")
151 def test_vf_module_id_parameter_type_and_parameter_name(heat_template):
152 check_parameter_type(heat_template, "vf_module_id", "string")
153 check_server_parameter_name(heat_template, "vf_module_id", "vf_module_id")
156 @validates("R-62428")
157 def test_vnf_name_parameter_type_and_parameter_name(heat_template):
158 check_parameter_type(heat_template, "vnf_name", "string")
159 check_server_parameter_name(heat_template, "vnf_name", "vnf_name")
162 @validates("R-39067")
163 def test_vf_module_name_parameter_type_and_parameter_name(heat_template):
164 check_parameter_type(heat_template, "vf_module_name", "string")
165 check_server_parameter_name(heat_template, "vf_module_name", "vf_module_name")
168 @validates("R-95430")
169 def test_vm_role_parameter_type_and_parameter_name(heat_template):
170 check_parameter_type(heat_template, "vm_role", "string")
171 check_server_parameter_name(heat_template, "vm_role", "vm_role")
174 @validates("R-54340")
175 def test_vf_module_index_parameter_type_and_parameter_name(heat_template):
176 check_parameter_type(heat_template, "vf_module_index", "number")
177 check_server_parameter_name(heat_template, "vf_module_index", "vf_module_index")