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
43 from tests.parametrizers import file_is_a_nested_template
45 from .helpers import validates
50 def check_parameter_type(heat_template, parameter, parameter_type):
52 Make sure these OS::Nova::Server parameters are defined w/
56 with open(heat_template) as fh:
59 # skip if resources are not defined
60 if "parameters" not in yml:
61 pytest.skip("No parameters specified in the heat template")
63 invalid_parameters = []
65 for k1, v1 in yml["parameters"].items():
66 if not isinstance(v1, dict):
71 if k1.find(parameter) == -1:
74 param_type = v1.get("type")
79 if param_type != parameter_type:
80 invalid_parameters.append(k1)
83 not invalid_parameters
84 ), "{} parameters must be defined as type {}: {}".format(
85 parameter, parameter_type, invalid_parameters
89 def check_server_parameter_name(heat_template, parameter, parameter_name):
91 Check each OS::Nova::Server metadata property
92 uses the same parameter name w/ get_param
95 with open(heat_template) as fh:
98 # skip if resources are not defined
99 if "resources" not in yml:
100 pytest.skip("No resources specified in the heat template")
102 invalid_parameters = []
104 for k1, v1 in yml["resources"].items():
105 if not isinstance(v1, dict):
110 if v1["type"] != "OS::Nova::Server":
113 metadata = v1.get("properties", {}).get("metadata", {}).get(parameter)
115 if not metadata or not isinstance(metadata, dict):
118 get_param = metadata.get("get_param")
123 if get_param != parameter_name:
124 invalid_parameters.append(
127 "metadata property": parameter_name,
128 "get_param": get_param,
132 assert not invalid_parameters, (
133 "metadata property {} must use get_param and "
134 "the parameter name must be {}: {}".format(
135 parameter, parameter_name, invalid_parameters
140 @validates("R-23311")
141 def test_availability_zone_parameter_type(yaml_file):
142 if file_is_a_nested_template(yaml_file):
143 pytest.skip("Not applicable in nested templates")
144 check_parameter_type(yaml_file, "availability_zone_", "string")
147 @validates("R-07507")
148 def test_vnf_id_parameter_type_and_parameter_name(yaml_file):
149 check_parameter_type(yaml_file, "vnf_id", "string")
150 check_server_parameter_name(yaml_file, "vnf_id", "vnf_id")
153 @validates("R-82134")
154 def test_vf_module_id_parameter_type_and_parameter_name(yaml_file):
155 check_parameter_type(yaml_file, "vf_module_id", "string")
156 check_server_parameter_name(yaml_file, "vf_module_id", "vf_module_id")
159 @validates("R-62428")
160 def test_vnf_name_parameter_type_and_parameter_name(yaml_file):
161 check_parameter_type(yaml_file, "vnf_name", "string")
162 check_server_parameter_name(yaml_file, "vnf_name", "vnf_name")
165 @validates("R-39067")
166 def test_vf_module_name_parameter_type_and_parameter_name(yaml_file):
167 check_parameter_type(yaml_file, "vf_module_name", "string")
168 check_server_parameter_name(yaml_file, "vf_module_name", "vf_module_name")
171 @validates("R-54340")
172 def test_vf_module_index_parameter_type_and_parameter_name(yaml_file):
173 check_parameter_type(yaml_file, "vf_module_index", "number")
174 check_server_parameter_name(yaml_file, "vf_module_index", "vf_module_index")