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.
43 from .utils.ports import is_reserved_port
44 from .utils.network_roles import get_network_role_from_port, property_uses_get_resource
48 def test_fixed_ips_format(heat_template):
50 Make sure all fixed_ips properties follow the allowed
54 ["fixed_ips", "string", "internal",
55 re.compile(r'(.+?)_int_(.+?)_ip_\d+')],
56 ["fixed_ips", "string", "internal",
57 re.compile(r'(.+?)_int_(.+?)_v6_ip_\d+')],
58 ["fixed_ips", "string", "external",
59 re.compile(r'(.+?)_ip_\d+')],
60 ["fixed_ips", "string", "external",
61 re.compile(r'(.+?)_v6_ip_\d+')],
62 ["fixed_ips", "comma_delimited_list", "internal",
63 re.compile(r'(.+?)_int_(.+?)_ips')],
64 ["fixed_ips", "comma_delimited_list", "internal",
65 re.compile(r'(.+?)_int_(.+?)_v6_ips')],
66 ["fixed_ips", "comma_delimited_list", "external",
67 re.compile(r'(.+?)_ips')],
68 ["fixed_ips", "comma_delimited_list", "external",
69 re.compile(r'(.+?)_v6_ips')],
72 with open(heat_template) as fh:
75 # skip if resources are not defined
76 if "resources" not in yml:
77 pytest.skip("No resources specified in the heat template")
79 invalid_fixed_ips = []
80 for k1, v1 in yml["resources"].items():
81 if not isinstance(v1, dict):
83 if "properties" not in v1:
85 if v1.get("type") != "OS::Neutron::Port":
87 if is_reserved_port(k1):
89 if property_uses_get_resource(v1, "network"):
91 network_role = get_network_role_from_port(v1)
93 for k2, v2 in v1["properties"].items():
97 if "ip_address" not in v3:
99 if "get_param" not in v3["ip_address"]:
102 valid_fixed_ip = False
104 param = v3["ip_address"]["get_param"]
105 if isinstance(param, list):
107 m = v4[3].match(param)
109 if v4[2] == "internal" and\
110 len(m.groups()) > 1 and\
111 m.group(2) == network_role:
112 valid_fixed_ip = True
114 elif v4[2] == "external" and\
115 len(m.groups()) > 0 and\
116 m.group(1).endswith("_" + network_role):
117 valid_fixed_ip = True
120 if not valid_fixed_ip:
121 invalid_fixed_ips.append(param)
123 assert not set(invalid_fixed_ips)