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============================================
37 from tests.helpers import validates, traverse
38 from tests.structures import Heat
43 If called sets found flag to True (used by traverse in uses_vf_module_index
49 def __call__(self, path, value):
53 def uses_vf_module_index(prop_value):
55 Returns True if prop_value uses vf_module_index, False otherwise
58 traverse(prop_value, "vf_module_index", finder)
62 def check_vf_module_index_errors(yaml_file, resource_type, property):
64 Finds all resources of resource_type where the property uses vf_module_index and
65 returns a set of all resource IDs that violate the condition.
67 resources = Heat(yaml_file).get_resource_by_type(resource_type)
69 for r_id, resource in resources.items():
71 resource_type in ("OS::Neutron::Port", "OS::ContrailV2::InstanceIp")
74 continue # rules do not apply to internal IPs
75 prop_value = resource.get("properties", {}).get(property)
76 if uses_vf_module_index(prop_value):
79 "The following {} resources use "
80 "vf_module_index to look up the {} property, "
81 "but that is not supported: {}"
82 ).format(resource_type, property, ", ".join(errors))
86 def test_no_vf_module_index_server_names(yaml_file):
87 check_vf_module_index_errors(yaml_file, "OS::Nova::Server", "name")
91 def test_no_vf_module_index_port_ips(yaml_file):
92 check_vf_module_index_errors(yaml_file, "OS::Neutron::Port", "fixed_ips")
96 def test_no_vf_module_index_contrail_ips(yaml_file):
97 check_vf_module_index_errors(
98 yaml_file, "OS::ContrailV2::InstanceIp", "instance_ip_address"