2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 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============================================
38 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
48 from .structures import Heat
49 from .helpers import validates
55 def test_nested_parameter_args(heat_template):
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".
66 type: comma_delimited_list
71 type: OS::Nova::Server
73 name: { get_param: [ ex1_vm_names, 0 ] }
75 vnf_id: { get_param: vnf_id }
77 get_param: [ cdl, { get_param: num }]
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")
91 has_nested_parameters = True
93 heat.nested_get(heat.parameters, param[0], "type")
97 "%s %s parameter type not %s"
98 % (key, param[0], Heat.type_cdl)
101 heat.nested_get(heat.parameters, nested_param, "type")
105 "%s %s nested parameter type not %s"
106 % (key, nested_param, Heat.type_num)
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())
111 if has_nested_parameters is False:
112 pytest.skip("No nested parameters found")