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 from .helpers import validates
48 @validates('R-71152', 'R-50436')
49 def test_nova_servers_correct_parameter_types(heat_template):
51 Make sure all nova servers have properly assigned types for the parameters
52 used for their name, image and flavor
54 key_values = ["name", "flavor", "image"]
57 re.compile(r'(.+?)_name_\d+')],
58 ["name", "comma_delimited_list",
59 re.compile(r'(.+?)_names')],
61 re.compile(r'(.+?)_flavor_name')],
63 re.compile(r'(.+?)_image_name')],
66 with open(heat_template) as fh:
69 # skip if parameters are not defined
70 if "parameters" not in yml:
71 pytest.skip("No parameters specified in the heat template")
73 # skip if resources are not defined
74 if "resources" not in yml:
75 pytest.skip("No resources specified in the heat template")
77 parameters = yml["parameters"]
79 invalid_nova_servers = []
81 for k1, v1 in yml["resources"].items():
82 if not isinstance(v1, dict):
84 if "properties" not in v1:
86 if v1.get("type") != "OS::Nova::Server":
89 valid_nova_server = True
90 for k2, v2 in v1["properties"].items():
91 if k2 not in key_values:
93 formats = [v for v in key_value_formats if v[0] == k2]
95 if "get_param" not in v2:
98 param = v2["get_param"]
99 if isinstance(param, list):
102 m = v3[2].match(param)
104 if parameters[param]:
105 param_spec = parameters[param]
106 if not param_spec["type"]:
107 valid_nova_server = False
108 elif param_spec["type"] != v3[1]:
109 valid_nova_server = False
111 if not valid_nova_server:
112 invalid_nova_servers.append(k1)
114 assert not set(invalid_nova_servers)