81cfc9a477fbe79c0b6555f1d6fc6bb1769b2b6a
[vvp/validation-scripts.git] / ice_validator / tests / test_no_unused_parameters_between_env_and_templates.py
1 # -*- coding: utf8 -*-
2 # ============LICENSE_START=======================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2018 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
7 #
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
12 #
13 #             http://www.apache.org/licenses/LICENSE-2.0
14 #
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.
20 #
21 #
22 #
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
27 #
28 #             https://creativecommons.org/licenses/by/4.0/
29 #
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.
35 #
36 # ============LICENSE_END============================================
37 #
38 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
39 #
40 import os
41 import pytest
42
43 from .helpers import validates, get_environment_pair
44
45
46 @pytest.mark.heat_only
47 @validates('R-90279', 'R-01896', 'R-26124')
48 def test_no_unused_parameters_between_env_and_templates(heat_template):
49     """
50     Check all defined parameters are used in the appropiate Heat template.
51     """
52     environment_pair = get_environment_pair(heat_template)
53     if not environment_pair:
54         pytest.skip("No heat/env pair could be identified")
55
56     env_parameters = set(environment_pair["eyml"]["parameters"].keys())
57     template_parameters = set(environment_pair["yyml"]["parameters"].keys())
58
59     extra_in_template = template_parameters.difference(env_parameters)
60     extra_in_env = env_parameters.difference(template_parameters)
61
62     msg = "Mismatched parameters detected for the template and environment pair " \
63           "with basename ({basename}). "
64     if extra_in_env:
65         msg += "The following parameters exist in the env file, but not the " \
66                "template: {extra_in_env}. "
67     if extra_in_template:
68         msg += "The following parameters exist in the template file, but not the " \
69                "environment file: {extra_in_template}"
70
71     assert not (extra_in_template or extra_in_env), msg.format(
72         basename=os.path.split(environment_pair["name"])[-1],
73         extra_in_env=", ".join(extra_in_env),
74         extra_in_template=", ".join(extra_in_template)
75     )