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 contrail interface route table routes
46 type: OS::ContrailV2::InterfaceRouteTable
47 depends_on: [resource name of OS::ContrailV2::ServiceInstance]
51 template: VNF_NAME_interface_route_table
53 VNF_NAME: { get_param: vnf_name }
54 interface_route_table_routes:
55 interface_route_table_routes_route: { get_param: fw_oam_route_prefixes }
56 service_instance_refs:
57 - get_resource: <resource name of OS::ContrailV2::ServiceInstance>
58 service_instance_refs_data:
59 - service_instance_refs_data_interface_type:
60 { get_param: oam_interface_type }
67 from .structures import Heat
68 from .helpers import validates
72 RE_ROUTE_ROUTE_PARAM = re.compile(
73 r"(?P<vm_type>.+)" r"_(?P<network_role>.+)" r"_route_prefixes" r"$"
77 def run_test(heat_template, validate):
78 """call validate for each routes route
80 heat = Heat(filepath=heat_template)
81 if not heat.resources:
82 pytest.skip("No resources found")
84 irts = heat.get_resource_by_type(
85 resource_type="OS::ContrailV2::InterfaceRouteTable"
88 pytest.skip("No Contrail InterfaceRouteTable found")
92 for rid, resource in irts.items():
93 routes_route = heat.nested_get(
96 "interface_route_table_routes",
97 "interface_route_table_routes_route",
99 if routes_route is None:
101 error = validate(heat, routes_route)
107 raise AssertionError(
108 "Bad OS::ContrailV2::InterfaceRouteTable: %s"
109 % (", ".join("%s: %s" % (rid, error) for rid, error in bad.items()))
112 pytest.skip("No Contrail routes_route found")
115 def validate_irt_route_param_format(heat, routes_route):
116 """ensure routes_route has proper format.
117 Returns error message string or None.
119 param = heat.nested_get(routes_route, "get_param")
121 return "missing routes_route get_param"
122 match = RE_ROUTE_ROUTE_PARAM.match(param)
124 return 'routes_route get_param "%s" must match "%s"' % (
126 RE_ROUTE_ROUTE_PARAM.pattern,
131 def validate_irt_route_param_type(heat, routes_route):
132 """ensure routes_route has proper type.
133 Returns error message string or None.
135 param = heat.nested_get(routes_route, "get_param")
138 if heat.nested_get(heat.parameters, param, "type") != "json":
140 'routes_route get_param "%s" '
141 'must have a parameter of type "json"' % param
146 # pylint: disable=invalid-name
149 @validates("R-28222")
150 def test_contrail_irt_route_param_format(heat_template):
152 If a VNF's Heat Orchestration Template
153 ``OS::ContrailV2::InterfaceRouteTable`` resource
154 ``interface_route_table_routes`` property
155 ``interface_route_table_routes_route`` map property parameter name
156 **MUST** follow the format
158 run_test(heat_template, validate_irt_route_param_format)
161 @validates("R-19756")
162 def test_contrail_irt_route_param_type(heat_template):
164 * ``{vm-type}_{network-role}_route_prefixes``
165 **MUST** be defined as type ``json``.
167 run_test(heat_template, validate_irt_route_param_type)