[VVP] updating validation scripts in dublin
[vvp/validation-scripts.git] / ice_validator / tests / test_nested_parameters.py
1 # -*- coding: utf8 -*-
2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 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
41 """heat parameters
42 """
43
44 import pytest
45 from tests import cached_yaml as yaml
46 from tests.structures import Resource
47
48 from .helpers import validates
49
50 VERSION = "1.0.0"
51
52
53 def check_nested_parameter_doesnt_change(yaml_file, parameter):
54
55     with open(yaml_file) as fh:
56         yml = yaml.load(fh)
57
58     # skip if resources are not defined
59     if "resources" not in yml:
60         pytest.skip("No resources specified in the heat template")
61
62     invalid_parameters = []
63
64     """
65     checking if property: { get_param: <parameter> }, then property == <parameter>
66
67     resource_id:
68         type: nested.yaml
69         properties:
70             property: { get_param: <parameter> }
71
72     resource_id:
73         type: OS::Heat::ResourceGroup
74         properties:
75             resource_def:
76                 properties:
77                     property: { get_param: <parameter> }
78     """
79     for resource_id, resource in yml.get("resources", {}).items():
80         r = Resource(resource_id=resource_id, resource=resource)
81         properties = r.get_nested_properties()
82         for k1, v1 in properties.items():
83             if (
84                 isinstance(v1, dict)
85                 and "get_param" in v1
86                 and parameter == v1.get("get_param")
87             ):
88                 if k1 != parameter:
89                     invalid_parameters.append(
90                         {
91                             "resource": r.resource_id,
92                             "nested parameter": k1,
93                             "parameter": parameter,
94                         }
95                     )
96
97     assert (
98         not invalid_parameters
99     ), "Invalid parameter name change detected in nested template {}".format(
100         invalid_parameters
101     )
102
103
104 @validates("R-70757")
105 def test_vm_role_doesnt_change_in_nested_template(yaml_file):
106     check_nested_parameter_doesnt_change(yaml_file, "vm_role")
107
108
109 @validates("R-44491")
110 def test_vnf_id_doesnt_change_in_nested_template(yaml_file):
111     check_nested_parameter_doesnt_change(yaml_file, "vnf_id")
112
113
114 @validates("R-86237")
115 def test_vf_module_id_doesnt_change_in_nested_template(yaml_file):
116     check_nested_parameter_doesnt_change(yaml_file, "vf_module_id")
117
118
119 @validates("R-16576")
120 def test_vnf_name_doesnt_change_in_nested_template(yaml_file):
121     check_nested_parameter_doesnt_change(yaml_file, "vnf_name")
122
123
124 @validates("R-49177")
125 def test_vf_module_name_doesnt_change_in_nested_template(yaml_file):
126     check_nested_parameter_doesnt_change(yaml_file, "vf_module_name")
127
128
129 @validates("R-22441")
130 def test_vf_module_index_name_doesnt_change_in_nested_template(yaml_file):
131     check_nested_parameter_doesnt_change(yaml_file, "vf_module_index")
132
133
134 @validates("R-62954")
135 def test_environment_context_name_doesnt_change_in_nested_template(yaml_file):
136     check_nested_parameter_doesnt_change(yaml_file, "environment_context")
137
138
139 @validates("R-75202")
140 def test_workload_context_name_doesnt_change_in_nested_template(yaml_file):
141     check_nested_parameter_doesnt_change(yaml_file, "workload_context")