Enforce black code format via pre-commit hook
[vvp/validation-scripts.git] / ice_validator / tests / test_contrail_resource_id.py
1 # -*- coding: utf8 -*-
2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
7 #
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
12 #
13 #             http://www.apache.org/licenses/LICENSE-2.0
14 #
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.
20 #
21 #
22 #
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
27 #
28 #             https://creativecommons.org/licenses/by/4.0/
29 #
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.
35 #
36 # ============LICENSE_END============================================
37 #
38 #
39
40 """
41 contrail
42 """
43
44 import pytest
45 from .structures import ContrailV2InterfaceRouteTableProcessor
46 from .structures import ContrailV2NetworkIpamProcessor
47 from .structures import ContrailV2PortTupleProcessor
48 from .structures import ContrailV2ServiceHealthCheckProcessor
49 from .structures import ContrailV2ServiceTemplateProcessor
50 from .utils.network_roles import get_network_roles
51 from .utils.vm_types import get_vm_types
52 from .structures import Heat
53 from .helpers import validates
54
55 VERSION = "2.0.0"
56
57
58 def run_test(heat_template, contrail_class, get_parts, part_name):
59     """
60     run test
61     """
62     heat = Heat(filepath=heat_template)
63     if not heat.resources:
64         pytest.skip("No resources found")
65     parts = get_parts(heat.resources)
66     if not parts:
67         pytest.skip("No %s found" % part_name)
68
69     contrail_resources = heat.get_resource_by_type(
70         resource_type=contrail_class.resource_type
71     )
72     if not contrail_resources:
73         pytest.skip("No %s resources found" % contrail_class.resource_type)
74
75     bad = []
76     for rid in contrail_resources:
77         if not any(heat.part_is_in_name(part, rid) for part in parts):
78             bad.append(rid)
79     if bad:
80         raise AssertionError(
81             "%s: %s"
82             " must have %s in %s"
83             % (contrail_class.resource_type, bad, part_name, list(parts))
84         )
85
86
87 # pylint: disable=invalid-name
88
89
90 @validates("R-81214")
91 def test_contrail_interfaceroutetable_resource_id(yaml_file):
92     """
93     A VNF's Heat Orchestration Template's Resource
94     ``OS::ContrailV2::InterfaceRouteTable``
95     Resource ID
96     **MUST**
97     contain the ``{network-role}``.
98     """
99     run_test(
100         yaml_file,
101         ContrailV2InterfaceRouteTableProcessor,
102         get_network_roles,
103         "network_role",
104     )
105
106
107 @validates("R-30753")
108 def test_contrail_networkipam_resource_id(yaml_file):
109     """
110     A VNF's Heat Orchestration Template's Resource
111     ``OS::ContrailV2::NetworkIpam``
112     Resource ID
113     **MUST**
114     contain the ``{network-role}``.
115     """
116     run_test(
117         yaml_file, ContrailV2NetworkIpamProcessor, get_network_roles, "network_role"
118     )
119
120
121 @validates("R-20065")
122 def test_contrail_porttuple_resource_id(yaml_file):
123     """
124     A VNF's Heat Orchestration Template's Resource
125     ``OS::ContrailV2::PortTuple``
126     Resource ID
127     **MUST**
128     contain the ``{vm-type}``.
129     """
130     run_test(yaml_file, ContrailV2PortTupleProcessor, get_vm_types, "vm_type")
131
132
133 @validates("R-76014")
134 def test_contrail_servicehealthcheck_resource_id(yaml_file):
135     """
136     A VNF's Heat Orchestration Template's Resource
137     ``OS::ContrailV2::ServiceHealthCheck``
138     Resource ID
139     **MUST**
140     contain the ``{vm-type}``.
141     """
142     run_test(yaml_file, ContrailV2ServiceHealthCheckProcessor, get_vm_types, "vm_type")
143
144
145 @validates("R-16437")
146 def test_contrail_servicetemplate_resource_id(yaml_file):
147     """
148     A VNF's Heat Orchestration Template's Resource
149     ``OS::ContrailV2::ServiceTemplate``
150     Resource ID
151     **MUST**
152     contain the ``{vm-type}``.
153     """
154     run_test(yaml_file, ContrailV2ServiceTemplateProcessor, get_vm_types, "vm_type")