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============================================
41 contrail interface route table routes
45 type: OS::ContrailV2::InterfaceRouteTable
46 depends_on: [resource name of OS::ContrailV2::ServiceInstance]
50 template: VNF_NAME_interface_route_table
52 VNF_NAME: { get_param: vnf_name }
53 interface_route_table_routes:
54 interface_route_table_routes_route: { get_param: fw_oam_route_prefixes }
55 service_instance_refs:
56 - get_resource: <resource name of OS::ContrailV2::ServiceInstance>
57 service_instance_refs_data:
58 - service_instance_refs_data_interface_type:
59 { get_param: oam_interface_type }
66 from .structures import Heat
67 from .helpers import validates
71 RE_ROUTE_ROUTE_PARAM = re.compile(
72 r"(?P<vm_type>.+)" r"_(?P<network_role>.+)" r"_route_prefixes" r"$"
76 def run_test(heat_template, validate):
77 """call validate for each routes route
79 heat = Heat(filepath=heat_template)
80 if not heat.resources:
81 pytest.skip("No resources found")
83 irts = heat.get_resource_by_type(
84 resource_type="OS::ContrailV2::InterfaceRouteTable"
87 pytest.skip("No Contrail InterfaceRouteTable found")
91 for rid, resource in irts.items():
92 routes_route = heat.nested_get(
95 "interface_route_table_routes",
96 "interface_route_table_routes_route",
98 if routes_route is None:
100 error = validate(heat, routes_route)
106 raise AssertionError(
107 "Bad OS::ContrailV2::InterfaceRouteTable: %s"
108 % (", ".join("%s: %s" % (rid, error) for rid, error in bad.items()))
111 pytest.skip("No Contrail routes_route found")
114 def validate_irt_route_param_format(heat, routes_route):
115 """ensure routes_route has proper format.
116 Returns error message string or None.
118 param = heat.nested_get(routes_route, "get_param")
120 return "missing routes_route get_param"
121 match = RE_ROUTE_ROUTE_PARAM.match(param)
123 return 'routes_route get_param "%s" must match "%s"' % (
125 RE_ROUTE_ROUTE_PARAM.pattern,
130 def validate_irt_route_param_type(heat, routes_route):
131 """ensure routes_route has proper type.
132 Returns error message string or None.
134 param = heat.nested_get(routes_route, "get_param")
137 if heat.nested_get(heat.parameters, param, "type") != "json":
139 'routes_route get_param "%s" '
140 'must have a parameter of type "json"' % param
145 # pylint: disable=invalid-name
148 @validates("R-28222")
149 def test_contrail_irt_route_param_format(yaml_file):
151 If a VNF's Heat Orchestration Template
152 ``OS::ContrailV2::InterfaceRouteTable`` resource
153 ``interface_route_table_routes`` property
154 ``interface_route_table_routes_route`` map property parameter name
155 **MUST** follow the format
157 run_test(yaml_file, validate_irt_route_param_format)
160 @validates("R-19756")
161 def test_contrail_irt_route_param_type(yaml_file):
163 * ``{vm-type}_{network-role}_route_prefixes``
164 **MUST** be defined as type ``json``.
166 run_test(yaml_file, validate_irt_route_param_type)