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.
42 resource property name
47 from .structures import Heat
48 from .helpers import validates
53 def get_non_servers(heat):
55 Return a dict of non servers. key is rid, value is resource
59 for rid, resource in heat.resources.items()
60 if heat.nested_get(resource, "type") != "OS::Nova::Server"
66 def test_non_server_name(heat_template):
68 If a VNF's Heat Orchestration Template contains the property ``name``
69 for a non ``OS::Nova::Server`` resource, the intrinsic function
70 ``str_replace`` **MUST** be used in conjunction with the ECOMP
71 supplied metadata parameter ``vnf_name`` to generate a unique value.
74 h = Heat(filepath=heat_template)
76 pytest.skip("No resources in this template")
78 non_servers = get_non_servers(h)
80 pytest.skip("No non-server resources in this template")
83 for rid, resource in non_servers.items():
84 name = h.nested_get(resource, "properties", "name")
88 # Make sure it uses str_replace
89 str_replace = name.get("str_replace") if hasattr(name, "get") else None
91 bad.append("{}'s name property does not use str_replace".format(rid))
94 # Make sure str_replace is properly formatted
95 if not all(key in str_replace for key in ("template", "params")):
98 "{}'s name property use of str_replace is "
99 + "missing template, params, or both"
103 params = str_replace["params"]
104 if not isinstance(params, dict):
107 "{}'s name property's use of str_replace.params is "
108 + "missing or invalid"
113 # Find the param that uses vnf_name
114 vnf_name_param = None
115 for key, value in params.items():
116 if not isinstance(value, dict):
118 if value.get("get_param", "") == "vnf_name":
121 if not vnf_name_param:
124 "{}'s name property's use str_replace does not "
125 + "use have a params that maps to the parameter "
126 "via {{get_param: vnf_name}}"
131 # make sure the VNF name is used in the template string
132 template = str_replace.get("template") or ""
133 if vnf_name_param not in template:
136 "{}'s name property's str_replace template does "
137 + "not incorporate vnf_name; expected {} in "
139 ).format(rid, vnf_name_param, template)
141 msg = "Improper name property for non-OS::Nova::Server resources. " + ". ".join(bad)