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.ports import is_reserved_port
44 from .utils.network_roles import get_network_role_from_port,\
45 property_uses_get_resource
49 def test_fixed_ips_format(heat_template):
51 Make sure all fixed_ips properties follow the allowed
55 ["fixed_ips", "string", "internal",
56 re.compile(r'(.+?)_int_(.+?)_ip_\d+')],
57 ["fixed_ips", "string", "internal",
58 re.compile(r'(.+?)_int_(.+?)_v6_ip_\d+')],
59 ["fixed_ips", "string", "external",
60 re.compile(r'(.+?)_ip_\d+')],
61 ["fixed_ips", "string", "external",
62 re.compile(r'(.+?)_v6_ip_\d+')],
63 ["fixed_ips", "comma_delimited_list", "internal",
64 re.compile(r'(.+?)_int_(.+?)_ips')],
65 ["fixed_ips", "comma_delimited_list", "internal",
66 re.compile(r'(.+?)_int_(.+?)_v6_ips')],
67 ["fixed_ips", "comma_delimited_list", "external",
68 re.compile(r'(.+?)_ips')],
69 ["fixed_ips", "comma_delimited_list", "external",
70 re.compile(r'(.+?)_v6_ips')],
73 with open(heat_template) as fh:
76 # skip if resources are not defined
77 if "resources" not in yml:
78 pytest.skip("No resources specified in the heat template")
80 invalid_fixed_ips = []
81 for k1, v1 in yml["resources"].items():
82 if not isinstance(v1, dict):
84 if "properties" not in v1:
86 if v1.get("type") != "OS::Neutron::Port":
88 if is_reserved_port(k1):
90 if property_uses_get_resource(v1, "network"):
92 network_role = get_network_role_from_port(v1)
94 for k2, v2 in v1["properties"].items():
98 if "ip_address" not in v3:
100 if "get_param" not in v3["ip_address"]:
103 valid_fixed_ip = False
105 param = v3["ip_address"]["get_param"]
106 if isinstance(param, list):
108 m = v4[3].match(param)
110 if v4[2] == "internal" and\
111 len(m.groups()) > 1 and\
112 m.group(2) == network_role:
113 valid_fixed_ip = True
115 elif v4[2] == "external" and\
116 len(m.groups()) > 0 and\
117 m.group(1).endswith("_" + network_role):
118 valid_fixed_ip = True
121 if not valid_fixed_ip:
122 invalid_fixed_ips.append(param)
124 assert not set(invalid_fixed_ips)