[VVP] updating validation scripts in dublin
[vvp/validation-scripts.git] / ice_validator / tests / test_contrail_instance_ip_resource_id.py
1 # -*- coding: utf8 -*-
2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 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 resources:
43 {vm-type}_server_{vm-type_index}
44 """
45 import pytest
46
47 from .structures import Heat
48 from .structures import ContrailV2InstanceIp
49 from .helpers import validates
50
51 VERSION = "1.1.0"
52
53
54 def run_test(heat_template, regex_names, network_flavor):
55     """run test
56     """
57     heat = Heat(filepath=heat_template)
58     heat_object_class = ContrailV2InstanceIp
59     resource_type = heat_object_class.resource_type
60     resources = heat.get_resource_by_type(resource_type=resource_type)
61     if not resources:
62         pytest.skip("No %s resources found" % resource_type)
63     bad = []
64     heat_object = heat_object_class()
65     rid_patterns = heat_object.get_rid_patterns()
66     for rid, resource in resources.items():
67         flavor = heat_object.get_network_flavor(resource)
68         if flavor != network_flavor:
69             continue
70         regex_name = heat_object.get_rid_match_tuple(rid)[0]
71         if regex_name in regex_names:
72             continue
73         bad.append(rid)
74     assert not bad, "%s resource ids %s must match one of %s" % (
75         network_flavor,
76         bad,
77         [v for k, v in rid_patterns.items() if k in regex_names],
78     )
79
80
81 # pylint: disable=invalid-name
82
83
84 @validates("R-53310", "R-46128")
85 def test_contrail_instance_ip_resource_id_external(heat_template):
86     """
87     A VNF's Heat Orchestration Template's Resource OS::ContrailV2::InstanceIp
88     that is configuring an IPv4 Address on a port attached to an external
89     network
90     Resource ID **MUST** use the naming convention
91
92     {vm-type}_{vm-type_index}_{network-role}_vmi_{vmi_index}
93             _IP_{index}
94
95     A VNF's Heat Orchestration Template's Resource OS::ContrailV2::InstanceIp
96     that is configuring an IPv6 Address on a port attached to an external
97     network
98     Resource ID **MUST** use the naming convention
99
100     {vm-type}_{vm-type_index}_{network-role}_vmi_{vmi_index}
101             _v6_IP_{index}
102
103     """
104
105     run_test(
106         heat_template,
107         regex_names=("ip", "v6_ip"),
108         network_flavor=ContrailV2InstanceIp.network_flavor_external,
109     )
110
111
112 @validates("R-62187", "R-87563")
113 def test_contrail_instance_ip_resource_id_internal(heat_template):
114     """
115     internal
116     {vm-type}_{vm-type_index}_int_{network-role}_vmi_{vmi_index}
117             _IP_{index}
118     {vm-type}_{vm-type_index}_int_{network-role}_vmi_{vmi_index}
119             _v6_IP_{index}
120     """
121     run_test(
122         heat_template,
123         regex_names=("int_ip", "int_v6_ip"),
124         network_flavor=ContrailV2InstanceIp.network_flavor_internal,
125     )
126
127
128 @validates("R-20947", "R-88540")
129 def test_contrail_instance_ip_resource_id_subint(heat_template):
130     """
131     subint
132     {vm-type}_{vm-type_index}_subint_{network-role}_vmi_{vmi_index}
133             _IP_{index}
134     {vm-type}_{vm-type_index}_subint_{network-role}_vmi_{vmi_index}
135             _v6_IP_{index}
136     """
137     run_test(
138         heat_template,
139         regex_names=("subint_ip", "subint_v6_ip"),
140         network_flavor=ContrailV2InstanceIp.network_flavor_subint,
141     )