[VVP] updating validation scripts in dublin
[vvp/validation-scripts.git] / ice_validator / tests / test_nested_parameter_args.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 collections
45
46 import pytest
47
48 from .structures import Heat
49 from .helpers import validates
50
51 VERSION = "1.0.0"
52
53
54 @validates("R-10834")
55 def test_nested_parameter_args(heat_template):
56     """
57     If a VNF’s Heat Orchestration Template resource attribute
58     property metadata uses a nested get_param, then the "outer"
59     get_param must take 2 arguments.  The first argument must be
60     a parameter of type "comma_delimited_list", and the second
61     argument must be the "inner" get_param whose value must be a
62     parameter of type "number".
63
64     parameters:
65         cdl:
66             type: comma_delimited_list
67         num:
68             type: number
69     resources:
70         ex1_nova_server_0:
71             type: OS::Nova::Server
72             properties:
73                 name: { get_param: [ ex1_vm_names, 0 ] }
74                 metadata:
75                     vnf_id: { get_param: vnf_id }
76                     vf_module_id:
77                         get_param: [ cdl, { get_param: num }]
78     """
79     heat = Heat(filepath=heat_template)
80     if not heat.resources:
81         pytest.skip("No resources found")
82     has_nested_parameters = False
83     bad = collections.defaultdict(list)
84     for rid, r in heat.resources.items():
85         metadata = heat.nested_get(r, "properties", "metadata", default={})
86         for key, value in metadata.items():
87             param = heat.nested_get(value, "get_param")
88             if isinstance(param, list) and len(param) == 2:
89                 nested_param = heat.nested_get(param[1], "get_param")
90                 if nested_param:
91                     has_nested_parameters = True
92                     if (
93                         heat.nested_get(heat.parameters, param[0], "type")
94                         != Heat.type_cdl
95                     ):
96                         bad[rid].append(
97                             "%s %s parameter type not %s"
98                             % (key, param[0], Heat.type_cdl)
99                         )
100                     if (
101                         heat.nested_get(heat.parameters, nested_param, "type")
102                         != Heat.type_num
103                     ):
104                         bad[rid].append(
105                             "%s %s nested parameter type not %s"
106                             % (key, nested_param, Heat.type_num)
107                         )
108     assert not bad, "resource ids with invalid nested parameter arguments\n    %s" % (
109         "\n    ".join("%s %s" % (k, ", ".join(v)) for k, v in bad.items())
110     )
111     if has_nested_parameters is False:
112         pytest.skip("No nested parameters found")