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 from itertools import chain
40 from tests.helpers import validates
41 from tests.structures import Heat
42 from tests.test_network_format import NETWORK_RESOURCE_TYPES, RE_INTERNAL_NETWORK_RID
44 INTERNAL_NETWORK_PARAMETERS = [
45 re.compile(r"int_(.+?)_net_id"),
46 re.compile(r"int_(.+?)_net_name"),
47 re.compile(r".*_int_(.+?)_floating(?:_v6)?_ip"),
48 re.compile(r".*_int_(.+?)_floating(?:_v6)?_ips"),
49 re.compile(r".*?_int_(.+?)(?:_v6)?_ips"),
50 re.compile(r".*?_int_(.+?)(?:_v6)?_ip_\d+"),
51 re.compile(r"int_(.+?)(?:_v6)?_subnet_id"),
52 re.compile(r"(?:.*_)?int_(.+?)_security_group"),
56 def get_network_ids(heat):
59 heat.get_resource_by_type(t)
60 for t in NETWORK_RESOURCE_TYPES
65 def get_internal_network_roles(heat_templates):
66 network_ids = chain.from_iterable(get_network_ids(t) for t in heat_templates)
67 matches = (RE_INTERNAL_NETWORK_RID.match(nid) for nid in network_ids)
68 return {m.groupdict().get("network_role", "").lower() for m in matches if m}
71 def first_match(param, patterns):
72 for pattern in patterns:
73 match = pattern.match(param)
80 def test_networks_exist_for_internal_network_params(yaml_files):
81 heat_templates = [t for t in map(Heat, yaml_files) if t.is_heat]
82 network_roles = get_internal_network_roles(heat_templates)
84 for heat in heat_templates:
85 for param in heat.parameters:
86 match = first_match(param, INTERNAL_NETWORK_PARAMETERS)
89 param_role = match.groups()[0]
90 if param_role not in network_roles:
92 "Parameter {} in template {} uses the internal network naming "
93 "convention, but no network with a resource ID of int_{}_network "
94 "was defined in any Heat template. Update the parameter to use "
95 "the naming convention for external networks or ensure the "
96 "internal network is defined in the VNF's Heat templates. Refer "
97 "to Networking section of Heat requirements for full definitions "
98 "of internal vs. external networks."
99 ).format(param, heat.basename, param_role))
101 assert not errors, "\n\n".join(errors)