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============================================
39 from tests.structures import Heat
40 from tests.helpers import parameter_type_to_heat_type, prop_iterator
41 from . import nested_dict
44 def check_parameter_format(yaml_file, regx, intext, resource_processor, *properties):
46 yaml_file: input file to check
47 regx: dictionary containing the regex to use to validate parameter
48 intext: internal or external
49 resource_processor: resource type specific helper, defined in structures.py
50 properties: arg list of property that is being checked
53 invalid_parameters = []
54 heat = Heat(filepath=yaml_file)
55 resource_type = resource_processor.resource_type
56 resources = heat.get_resource_by_type(resource_type)
57 heat_parameters = heat.parameters
58 for rid, resource in resources.items():
59 resource_intext, port_match = resource_processor.get_rid_match_tuple(rid)
61 continue # port resource ID not formatted correctely
64 resource_intext != intext
65 ): # skipping if type (internal/external) doesn't match
68 for param in prop_iterator(resource, *properties):
71 and isinstance(param, dict)
72 and "get_resource" not in param
73 and "get_attr" not in param
76 # checking parameter uses get_param
77 parameter = param.get("get_param")
80 "Unexpected parameter format for {} {} property {}: {}. "
81 + "Please consult the heat guidelines documentation for details."
82 ).format(resource_type, rid, properties, param)
83 invalid_parameters.append(msg) # should this be a failure?
86 # getting parameter if the get_param uses list, and getting official HEAT parameter type
87 parameter_type = parameter_type_to_heat_type(parameter)
88 if parameter_type == "comma_delimited_list":
89 parameter = parameter[0]
90 elif parameter_type != "string":
93 # checking parameter format = parameter type defined in parameters section
94 heat_parameter_type = nested_dict.get(heat_parameters, parameter, "type")
95 if not heat_parameter_type or heat_parameter_type != parameter_type:
97 "{} {} parameter {} defined as type {} "
98 + "is being used as type {} in the heat template"
100 resource_type, properties, parameter, heat_parameter_type, parameter_type
102 invalid_parameters.append(msg) # should this actually be an error?
105 # if parameter type is not in regx dict, then it is not supported by automation
106 regx_dict = regx[resource_intext].get(parameter_type)
109 "WARNING: {} {} parameter {} defined as type {} "
110 "is not supported by platform automation. If this VNF is not able "
111 "to adhere to this requirement, please consult the Heat Orchestration "
112 "Template guidelines for alternative solutions. If already adhering to "
113 "an alternative provided by the heat guidelines, please disregard this "
115 ).format(resource_type, properties, parameter, parameter_type)
116 invalid_parameters.append(msg)
119 # checking if param adheres to guidelines format
120 regexp = regx[resource_intext][parameter_type]["machine"]
121 readable_format = regx[resource_intext][parameter_type]["readable"]
122 match = regexp.match(parameter)
124 msg = "{} {} property {} parameter {} does not follow {} format {}".format(
125 resource_type, rid, properties, parameter, resource_intext, readable_format
127 invalid_parameters.append(msg)
130 # checking that parameter includes correct vm_type/network_role
131 parameter_checks = regx.get("parameter_to_resource_comparisons", [])
132 for check in parameter_checks:
133 resource_match = port_match.group(check)
136 and not parameter.startswith(resource_match)
137 and parameter.find("_{}_".format(resource_match)) == -1
140 "{0} {1} property {2} parameter "
141 "{3} {4} does match resource {4} {5}"
142 ).format(resource_type, rid, properties, parameter, check, resource_match)
143 invalid_parameters.append(msg)
146 assert not invalid_parameters, "%s" % "\n".join(invalid_parameters)
149 def get_list_of_ports_attached_to_nova_server(nova_server):
150 networks_list = nova_server.get("properties", {}).get("networks")
154 for network in networks_list:
155 network_prop = network.get("port")
157 pid = network_prop.get("get_param")
159 pid = network_prop.get("get_resource")