[VVP] stand alone tool, script updates
[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 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
39 #
40
41 """
42 contrail
43 """
44
45 import pytest
46 from .structures import ContrailV2InterfaceRouteTableProcessor
47 from .structures import ContrailV2NetworkIpamProcessor
48 from .structures import ContrailV2PortTupleProcessor
49 from .structures import ContrailV2ServiceHealthCheckProcessor
50 from .structures import ContrailV2ServiceTemplateProcessor
51 from .utils.network_roles import get_network_roles
52 from .utils.vm_types import get_vm_types
53 from .structures import Heat
54 from .helpers import validates
55
56 VERSION = "2.0.0"
57
58
59 def run_test(heat_template, contrail_class, get_parts, part_name):
60     """
61     run test
62     """
63     heat = Heat(filepath=heat_template)
64     if not heat.resources:
65         pytest.skip("No resources found")
66     parts = get_parts(heat.resources)
67     if not parts:
68         pytest.skip("No %s found" % part_name)
69
70     contrail_resources = heat.get_resource_by_type(
71         resource_type=contrail_class.resource_type
72     )
73     if not contrail_resources:
74         pytest.skip("No %s resources found" % contrail_class.resource_type)
75
76     bad = []
77     for rid in contrail_resources:
78         if not any(heat.part_is_in_name(part, rid) for part in parts):
79             bad.append(rid)
80     if bad:
81         raise AssertionError(
82             "%s: %s"
83             " must have %s in %s"
84             % (contrail_class.resource_type, bad, part_name, list(parts))
85         )
86
87
88 # pylint: disable=invalid-name
89
90
91 @validates("R-81214")
92 def test_contrail_interfaceroutetable_resource_id(heat_template):
93     """
94     A VNF's Heat Orchestration Template's Resource
95     ``OS::ContrailV2::InterfaceRouteTable``
96     Resource ID
97     **MUST**
98     contain the ``{network-role}``.
99     """
100     run_test(
101         heat_template,
102         ContrailV2InterfaceRouteTableProcessor,
103         get_network_roles,
104         "network_role",
105     )
106
107
108 @validates("R-30753")
109 def test_contrail_networkipam_resource_id(heat_template):
110     """
111     A VNF's Heat Orchestration Template's Resource
112     ``OS::ContrailV2::NetworkIpam``
113     Resource ID
114     **MUST**
115     contain the ``{network-role}``.
116     """
117     run_test(
118         heat_template, ContrailV2NetworkIpamProcessor, get_network_roles, "network_role"
119     )
120
121
122 @validates("R-20065")
123 def test_contrail_porttuple_resource_id(heat_template):
124     """
125     A VNF's Heat Orchestration Template's Resource
126     ``OS::ContrailV2::PortTuple``
127     Resource ID
128     **MUST**
129     contain the ``{vm-type}``.
130     """
131     run_test(heat_template, ContrailV2PortTupleProcessor, get_vm_types, "vm_type")
132
133
134 @validates("R-76014")
135 def test_contrail_servicehealthcheck_resource_id(heat_template):
136     """
137     A VNF's Heat Orchestration Template's Resource
138     ``OS::ContrailV2::ServiceHealthCheck``
139     Resource ID
140     **MUST**
141     contain the ``{vm-type}``.
142     """
143     run_test(
144         heat_template, ContrailV2ServiceHealthCheckProcessor, get_vm_types, "vm_type"
145     )
146
147
148 @validates("R-16437")
149 def test_contrail_servicetemplate_resource_id(heat_template):
150     """
151     A VNF's Heat Orchestration Template's Resource
152     ``OS::ContrailV2::ServiceTemplate``
153     Resource ID
154     **MUST**
155     contain the ``{vm-type}``.
156     """
157     run_test(heat_template, ContrailV2ServiceTemplateProcessor, get_vm_types, "vm_type")