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