2 # ============LICENSE_START=======================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2018 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.
44 from tests import cached_yaml as yaml
46 from .helpers import validates
48 from .utils.vm_types import get_vm_types_for_resource
49 from .utils.vm_types import get_vm_types
51 from .utils.network_roles import get_network_roles
55 def test_vm_type_consistent_on_nova_servers(heat_template):
57 Make sure all nova servers have properly formatted properties
58 for their name, image and flavor
60 with open(heat_template) as fh:
63 # skip if resources are not defined
64 if "resources" not in yml:
65 pytest.skip("No resources specified in the heat template")
67 invalid_nova_servers = []
68 for k, v in yml["resources"].items():
69 if not isinstance(v, dict):
71 if v.get('type') != 'OS::Nova::Server':
73 if 'properties' not in v:
76 vm_types = get_vm_types_for_resource(v)
77 if len(vm_types) != 1:
78 invalid_nova_servers.append(k)
80 assert not set(invalid_nova_servers), \
81 "vm_types not consistant on the following resources {}" \
82 .format(invalid_nova_servers)
87 def test_vm_type_network_role_collision(yaml_file):
88 with open(yaml_file) as fh:
91 # skip if resources are not defined
92 if "resources" not in yml:
93 pytest.skip("No resources specified in the heat template")
95 resources = yml["resources"]
97 vm_types = get_vm_types(resources)
98 network_roles = get_network_roles(resources)
101 for nr in network_roles:
103 if vt in nr or nr in vt:
104 collisions.append({"vm_type": vt, "network_role": nr})
106 assert not collisions, \
107 "vm_type and network_role should not be substrings {}" .format(collisions)
110 @validates('R-50436',
113 def test_nova_server_flavor_parameter(yaml_file):
116 check_nova_parameter_format(prop, yaml_file)
119 @validates('R-51430',
122 def test_nova_server_name_parameter(yaml_file):
125 check_nova_parameter_format(prop, yaml_file)
128 @validates('R-71152',
131 def test_nova_server_image_parameter(yaml_file):
134 check_nova_parameter_format(prop, yaml_file)
137 def check_nova_parameter_format(prop, yaml_file):
141 "name": re.compile(r'(.+?)_name_\d+$'),
142 "flavor": re.compile(r'(.+?)_flavor_name$'),
143 "image": re.compile(r'(.+?)_image_name$')
145 "comma_delimited_list": {
146 "name": re.compile(r'(.+?)_names$')
150 with open(yaml_file) as fh:
153 # skip if resources are not defined
154 if "resources" not in yml:
155 pytest.skip("No resources specified in the heat template")
157 # skip if resources are not defined
158 if "parameters" not in yml:
159 pytest.skip("No parameters specified in the heat template")
161 invalid_parameters = []
163 for k, v in yml["resources"].items():
164 if not isinstance(v, dict):
166 if v.get('type') != 'OS::Nova::Server':
169 prop_param = v.get("properties", {}) \
174 pytest.skip("{} doesn't have property {}".format(k, prop))
175 elif isinstance(prop_param, list):
176 prop_param = prop_param[0]
178 template_param_type = yml.get("parameters", {}) \
179 .get(prop_param, {}) \
182 if not template_param_type:
183 pytest.skip("could not determine param type for {}".format(prop_param))
185 format_match = formats.get(template_param_type, {}) \
188 if not format_match or not format_match.match(prop_param):
189 invalid_parameters.append(prop_param)
191 assert not set(invalid_parameters), \
192 "invalid {} parameters detected {}" \
193 .format(prop, invalid_parameters)