2 # ============LICENSE_START=======================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2018 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============================================
41 from .helpers import validates, get_environment_pair
44 def get_keys(template, key):
46 Gets the set of keys from an expected dict from the ``template`` mapped to
47 the ``key``. If the key is not found, or is not a dict, then an empty
50 value = template.get(key)
51 if not value or not hasattr(value, "keys"):
54 return set(value.keys())
57 @pytest.mark.heat_only
58 @validates("R-01896", "R-26124")
59 def test_no_unused_parameters_between_env_and_templates(heat_template):
61 Check all defined parameters are used in the appropriate Heat template.
63 environment_pair = get_environment_pair(heat_template)
64 if not environment_pair:
65 pytest.skip("No heat/env pair could be identified")
67 env_parameters = get_keys(environment_pair["eyml"], "parameters")
68 template_parameters = get_keys(environment_pair["yyml"], "parameters")
70 extra_in_template = template_parameters.difference(env_parameters)
71 extra_in_env = env_parameters.difference(template_parameters)
74 "Mismatched parameters detected for the template and environment pair "
75 "({basename}). Ensure the parameters exist in both "
76 "templates indented under their respective parameters sections. "
80 "The following parameters exist in the env file, but not the "
81 "template: {extra_in_env}. "
85 "The following parameters exist in the template file, but not the "
86 "environment file: {extra_in_template}"
89 assert not (extra_in_template or extra_in_env), msg.format(
90 basename=os.path.split(environment_pair["name"])[-1],
91 extra_in_env=", ".join(extra_in_env),
92 extra_in_template=", ".join(extra_in_template),