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============================================
43 from tests import cached_yaml as yaml
44 from tests.structures import Resource
45 from .helpers import validates
46 from .utils.nested_iterables import is_pseudo_param
51 def check_nested_parameter_doesnt_change(yaml_file):
53 with open(yaml_file) as fh:
56 # skip if resources are not defined
57 if "resources" not in yml:
58 pytest.skip("No resources specified in the heat template")
60 invalid_parameters = []
62 checking if property: { get_param: parameter }, then property == parameter
67 property: { get_param: parameter }
70 type: OS::Heat::ResourceGroup
74 property: { get_param: parameter }
76 for resource_id, resource in yml.get("resources", {}).items():
77 resource_type = resource.get("type")
78 if resource_type and (
79 resource_type.endswith("yaml")
80 or resource_type.endswith("yml")
81 or resource_type == "OS::Heat::ResourceGroup"
83 # workaround for subinterfaces
84 metadata = resource.get("metadata")
86 subinterface_type = metadata.get("subinterface_type")
87 if subinterface_type and subinterface_type == "network_collection":
90 r = Resource(resource_id=resource_id, resource=resource)
91 properties = r.get_nested_properties()
92 for k1, v1 in properties.items():
93 if isinstance(v1, dict) and "get_param" in v1:
94 parameter = v1.get("get_param")
95 if isinstance(parameter, list):
96 parameter = parameter[0]
98 if is_pseudo_param(parameter):
102 invalid_parameters.append(
104 "resource": r.resource_id,
105 "nested parameter": k1,
106 "parameter": parameter,
112 not invalid_parameters
113 ), "Invalid parameter name change detected in nested template {}".format(
118 @validates("R-708564")
119 def test_parameter_name_doesnt_change_in_nested_template(yaml_file):
120 check_nested_parameter_doesnt_change(yaml_file)