2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2019 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============================================
42 from tests.parametrizers import get_nested_files
43 from tests.utils.network_roles import get_network_type_from_port
44 from .structures import Heat
45 from .helpers import validates, load_yaml
48 RE_BASE = re.compile(r"(^base$)|(^base_)|(_base_)|(_base$)")
51 def get_base_template_filepath(yaml_files):
52 """Return first filepath to match RE_BASE
54 for filepath in yaml_files:
55 basename, __ = os.path.splitext(os.path.basename(filepath))
56 if RE_BASE.search(basename) and basename.find("volume") == -1:
62 def test_neutron_port_internal_network_v2(yaml_files):
63 base_path = get_base_template_filepath(yaml_files)
64 nested_template_paths = get_nested_files(yaml_files)
66 for yaml_file in yaml_files:
67 if yaml_file == base_path or yaml_file in nested_template_paths:
68 continue # Only applies to incremental modules
69 heat = Heat(filepath=yaml_file)
70 internal_ports = {r_id: p for r_id, p in heat.neutron_port_resources.items()
71 if get_network_type_from_port(p) == "internal"}
72 for r_id, port in internal_ports.items():
73 props = port.get("properties") or {}
74 network_value = props.get("network") or {}
75 if not isinstance(network_value, dict):
77 if "get_param" not in network_value:
78 continue # Not connecting to network outside the template
79 param = network_value.get("get_param")
80 base_heat = load_yaml(base_path)
81 base_outputs = base_heat.get("outputs") or {}
82 if not param.endswith("_net_id"):
84 "Internal network {} is attached to port {}, but the "
85 "network must be attached via UUID of the network not "
86 "the name (ex: int_{{network-role}}_net_id)."
87 ).format(param, r_id))
88 if param not in base_outputs:
90 "Internal network {} is attached to port {}, but network "
91 "is not defined as an output in the base module ({})."
92 ).format(param, r_id, base_path))
94 assert not errors, " ".join(errors)