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.
44 from .utils.vm_types import get_vm_type_for_nova_server
45 from .utils.network_roles import get_network_role_from_port,\
46 get_network_type_from_port
49 def test_port_resource_ids(heat_template):
51 Check that all resource ids for ports follow the right
52 naming convention to include the {vm_type} of the
53 nova server it is associated to and also contains the
54 {network_role} of the network it is associated with
56 with open(heat_template) as fh:
59 # skip if resources are not defined
60 if "resources" not in yml:
61 pytest.skip("No resources specified in the heat template")
64 'internal': re.compile(r'(.+?)_\d+_int_(.+?)_\d+_port'),
65 'external': re.compile(r'(.+?)_\d+_(.+?)_\d+_port'),
67 resources = yml['resources']
70 for k, v in resources.items():
71 if not isinstance(v, dict):
75 if v['type'] not in 'OS::Nova::Server':
77 if 'properties' not in v:
79 if 'networks' not in v['properties']:
83 has_network_role = True
86 vm_type = get_vm_type_for_nova_server(v)
89 vm_type = vm_type.lower()
91 # get all ports associated with the nova server
92 properties = v['properties']
93 for v2 in properties['networks']:
94 for k3, v3 in v2.items():
97 if not isinstance(v3, dict):
100 if 'get_param' in v3:
102 elif 'get_resource' in v3:
103 port_id = v3['get_resource']
104 if not resources[port_id]:
106 port_resource = resources[port_id]
107 port_id = port_id.lower()
111 has_vm_type = vm_type+"_" in port_id
114 network_role = get_network_role_from_port(port_resource)
117 network_role = network_role.lower()
119 network_type = get_network_type_from_port(port_resource)
124 if network_type == 'internal':
126 has_network_role = prepend+network_role+"_" in port_id
128 # match the assumed naming convention for ports
129 # if the specified port is provided via get_param
130 network_type = 'external'
131 if "int_" in port_id:
132 network_type = 'internal'
133 if port_patterns[network_type].match(port_id):
134 has_network_role = True
136 if has_vm_type and has_network_role:
138 invalid_ports.append(port_id)
140 assert not set(invalid_ports)