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.
46 def test_nova_servers_correct_parameter_types(heat_template):
48 Make sure all nova servers have properly assigned types for the parameters
49 used for their name, image and flavor
51 key_values = ["name", "flavor", "image"]
54 re.compile(r'(.+?)_name_\d+')],
55 ["name", "comma_delimited_list",
56 re.compile(r'(.+?)_names')],
58 re.compile(r'(.+?)_flavor_name')],
60 re.compile(r'(.+?)_image_name')],
63 with open(heat_template) as fh:
66 # skip if parameters are not defined
67 if "parameters" not in yml:
68 pytest.skip("No parameters specified in the heat template")
70 # skip if resources are not defined
71 if "resources" not in yml:
72 pytest.skip("No resources specified in the heat template")
74 parameters = yml["parameters"]
76 invalid_nova_servers = []
78 for k1, v1 in yml["resources"].items():
79 if not isinstance(v1, dict):
81 if "properties" not in v1:
83 if v1.get("type") != "OS::Nova::Server":
86 valid_nova_server = True
87 for k2, v2 in v1["properties"].items():
88 if k2 not in key_values:
90 formats = [v for v in key_value_formats if v[0] == k2]
92 if "get_param" not in v2:
95 param = v2["get_param"]
96 if isinstance(param, list):
99 m = v3[2].match(param)
101 if parameters[param]:
102 param_spec = parameters[param]
103 if not param_spec["type"]:
104 valid_nova_server = False
105 elif param_spec["type"] != v3[1]:
106 valid_nova_server = False
108 if not valid_nova_server:
109 invalid_nova_servers.append(k1)
111 assert not set(invalid_nova_servers)