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.
43 from .utils.network_roles import get_network_role_from_port,\
44 property_uses_get_resource
48 def test_subnet_format(heat_template):
50 Make sure all subnet properties follow the allowed naming
54 ["subnet_id", "string", "internal",
55 re.compile(r'int_(.+?)_subnet_id')],
56 ["subnet_id", "string", "internal",
57 re.compile(r'int_(.+?)_v6_subnet_id')],
58 ["subnet_id", "string", "external",
59 re.compile(r'(.+?)_subnet_id')],
60 ["subnet_id", "string", "external",
61 re.compile(r'(.+?)_v6_subnet_id')],
64 with open(heat_template) as fh:
67 # skip if resources are not defined
68 if "resources" not in yml:
69 pytest.skip("No resources specified in the heat template")
72 for v1 in yml["resources"].values():
73 if not isinstance(v1, dict):
75 if "properties" not in v1:
77 if v1.get("type") != "OS::Neutron::Port":
79 if property_uses_get_resource(v1, "network"):
81 network_role = get_network_role_from_port(v1)
83 # get the network param to define the network_type
85 network_param = v1["properties"]["network"]["get_param"]
89 # define the network_type
90 network_type = 'external'
91 if network_param.startswith('int_'):
92 network_type = 'internal'
94 for k2, v2 in v1["properties"].items():
99 if "subnet_id" not in v3:
102 subnet_id = v3["subnet_id"]
104 if v4[2] != network_type:
107 # get the param or resource
108 if network_type == "external":
109 param_or_res = subnet_id["get_param"]
110 elif network_type == "internal":
111 if subnet_id.get("get_param"):
112 param_or_res = subnet_id["get_param"]
113 elif subnet_id.get("get_resource"):
114 param_or_res = subnet_id["get_resource"]
120 m = v4[3].match(param_or_res)
123 if snr.replace("_v6", "") != network_role:
124 invalid_subnets.append(param_or_res)
126 assert not set(invalid_subnets)