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============================================
44 from tests.structures import ContrailV2InstanceIpProcessor, Heat
45 from tests.helpers import validates, get_base_template_from_yaml_files, get_param
46 from tests.utils.incrementals import get_incremental_modules
47 from tests.utils.ports import check_parameter_format
49 RE_EXTERNAL_PARAM_IIP = re.compile( # match pattern
50 r"(?P<vm_type>.+)_(?P<network_role>.+?)(_v6)?_ip_(?P<ip_index>.+)$"
53 RE_EXTERNAL_PARAM_IIPS = re.compile( # match pattern
54 r"(?P<vm_type>.+)_(?P<network_role>.+?)(_v6)?_ips$"
57 RE_INTERNAL_PARAM_IIP = re.compile( # match pattern
58 r"(?P<vm_type>.+)_int_(?P<network_role>.+?)(_v6)?_ip_(?P<ip_index>.+)$"
61 RE_INTERNAL_PARAM_IIPS = re.compile( # match pattern
62 r"(?P<vm_type>.+)_int_(?P<network_role>.+?)(_v6)?_ips$"
68 "readable": "{vm-type}_{network-role}_ip_{ip-index} or {vm-type}_{network-role}_v6_ip_{ip-index}",
69 "machine": RE_EXTERNAL_PARAM_IIP,
71 "comma_delimited_list": {
72 "readable": "{vm-type}_{network-role}_ips or {vm-type}_{network-role}_v6_ips",
73 "machine": RE_EXTERNAL_PARAM_IIPS,
78 "readable": "{vm-type}_int_{network-role}_ip_{ip-index} or {vm-type}_int_{network-role}_v6_ip_{ip-index}",
79 "machine": RE_INTERNAL_PARAM_IIP,
81 "comma_delimited_list": {
82 "readable": "{vm-type}_int_{network-role}_ips or {vm-type}_int_{network-role}_v6_ips",
83 "machine": RE_INTERNAL_PARAM_IIPS,
86 "parameter_to_resource_comparisons": ["vm_type", "network_role"],
90 RE_EXTERNAL_PARAM_SID = re.compile( # match pattern
91 r"(?P<network_role>.+?)(_v6)?_subnet_id$"
94 RE_INTERNAL_PARAM_SID = re.compile( # match pattern
95 r"int_(?P<network_role>.+?)(_v6)?_subnet_id$"
101 "readable": "{network-role}_subnet_id or {network-role}_v6_subnet_id",
102 "machine": RE_EXTERNAL_PARAM_SID,
107 "readable": "int_{network-role}_subnet_id or int_{network-role}_v6_subnet_id",
108 "machine": RE_INTERNAL_PARAM_SID,
111 "parameter_to_resource_comparisons": ["network_role"],
115 @validates("R-100000", "R-100010", "R-100030", "R-100050", "R-100070")
116 def test_contrail_external_instance_ip_address_parameter(yaml_file):
117 check_parameter_format(yaml_file, iip_regx_dict, "external", ContrailV2InstanceIpProcessor, "instance_ip_address")
120 @validates("R-100000", "R-100090", "R-100110", "R-100130", "R-100150")
121 def test_contrail_internal_instance_ip_address_parameter(yaml_file):
122 check_parameter_format(yaml_file, iip_regx_dict, "internal", ContrailV2InstanceIpProcessor, "instance_ip_address")
125 @validates("R-100190", "R-100200", "R-100220")
126 def test_contrail_external_instance_subnet_id_parameter(yaml_file):
127 check_parameter_format(yaml_file, sid_regx_dict, "external", ContrailV2InstanceIpProcessor, "subnet_uuid")
130 @validates("R-100190", "R-100240", "R-100260")
131 def test_contrail_internal_instance_subnet_id_parameter(yaml_file):
132 check_parameter_format(yaml_file, sid_regx_dict, "internal", ContrailV2InstanceIpProcessor, "subnet_uuid")
135 @validates("R-100240", "R-100260")
136 def test_contrail_incremental_module_internal_subnet_usage(yaml_files):
137 base_path = get_base_template_from_yaml_files(yaml_files)
139 pytest.skip("No base module detected to check")
140 base_outputs = Heat(filepath=base_path).outputs
141 incremental_modules = get_incremental_modules(yaml_files)
143 for module in incremental_modules:
144 heat = Heat(filepath=module)
145 ips = heat.get_resource_by_type(ContrailV2InstanceIpProcessor.resource_type)
146 internal_ips = ((r_id, props) for r_id, props in ips.items() if "_int_" in r_id)
147 for r_id, ip in internal_ips:
148 subnet_uuid = (ip.get("properties") or {}).get("subnet_uuid")
149 subnet_param = get_param(subnet_uuid)
152 if subnet_param not in base_outputs:
154 "Resource ({}) is designated as an internal IP, but its "
155 "subnet_uuid parameter ({}) does not refer to subnet in "
156 "this template nor is it defined in the output section "
157 "of the base module ({})"
158 ).format(r_id, subnet_param, os.path.basename(base_path)))
159 assert not errors, ". ".join(errors)