2 # ============LICENSE_START=======================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2019 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============================================
40 from tests.helpers import validates
41 from tests.structures import Heat
42 from tests.utils import nested_dict
44 SERVER_ID_PATTERN = re.compile(r"\w+_server_(\d+)")
45 PORT_ID_PATTERN = re.compile(r"\w+_(\d+)_\w+\d+")
48 def get_ports(server):
49 props = server.get("properties") or {}
50 networks = props.get("networks") or []
51 for network in networks:
52 r_id = nested_dict.get(network, "port", "get_resource")
57 @validates("R-304011")
58 def test_server_and_port_vmtype_indices_match(yaml_file):
59 # NOTE: This test is only going to validate that the index values
60 # match between the between the ports and server names. Other
61 # tests already cover the other aspects of this requirement
63 heat = Heat(filepath=yaml_file)
64 servers = heat.get_resource_by_type("OS::Nova::Server")
66 for r_id, server in servers.items():
67 match = SERVER_ID_PATTERN.match(r_id)
69 continue # other tests cover valid server ID format
70 server_index = match.group(1)
71 ports = get_ports(server)
73 port_match = PORT_ID_PATTERN.match(port)
75 port_vm_index = port_match.group(1)
76 if port_vm_index != server_index:
79 "{{vm-type_index}} ({}) in port ID ({}) "
80 + "does not match the {{index}} ({}) in the "
81 + "servers resource ID ({})"
82 ).format(port_vm_index, port, server_index, r_id)
84 assert not errors, ". ".join(errors)