[VVP] Adding tests for new reqs from VNFRQTS-630
[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 © 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 import pytest
40
41 from .structures import Heat
42 from .structures import ContrailV2InstanceIpProcessor
43 from .helpers import validates
44
45 VERSION = "2.0.0"
46
47
48 def run_test(heat_template, regex_names, network_flavor):
49     """run test
50     """
51     heat = Heat(filepath=heat_template)
52     processor = ContrailV2InstanceIpProcessor
53     resource_type = processor.resource_type
54     resources = heat.get_resource_by_type(resource_type=resource_type)
55     if not resources:
56         pytest.skip("No %s resources found" % resource_type)
57     bad = []
58     rid_patterns = processor.get_rid_patterns()
59     for rid, resource in resources.items():
60         flavor = processor.get_network_flavor(resource)
61         if flavor != network_flavor:
62             continue
63
64         regex_name = processor.get_rid_match_tuple(rid)[0]
65         if regex_name and regex_name in regex_names:
66             continue
67         bad.append(rid)
68     assert not bad, "%s resource ids %s must match one of %s" % (
69         network_flavor,
70         bad,
71         [v for k, v in rid_patterns.items() if k in regex_names],
72     )
73
74
75 # pylint: disable=invalid-name
76
77
78 @validates("R-53310", "R-46128")
79 def test_contrail_instance_ip_resource_id_external(yaml_file):
80     """
81     A VNF's Heat Orchestration Template's Resource OS::ContrailV2::InstanceIp
82     that is configuring an IPv4 Address on a port attached to an external
83     network
84     Resource ID **MUST** use the naming convention
85
86     {vm-type}_{vm-type_index}_{network-role}_vmi_{vmi_index}
87             _IP_{index}
88
89     A VNF's Heat Orchestration Template's Resource OS::ContrailV2::InstanceIp
90     that is configuring an IPv6 Address on a port attached to an external
91     network
92     Resource ID **MUST** use the naming convention
93
94     {vm-type}_{vm-type_index}_{network-role}_vmi_{vmi_index}
95             _v6_IP_{index}
96
97     """
98
99     run_test(
100         yaml_file,
101         regex_names=("external"),
102         network_flavor=ContrailV2InstanceIpProcessor.network_flavor_external,
103     )
104
105
106 @validates("R-62187", "R-87563")
107 def test_contrail_instance_ip_resource_id_internal(yaml_file):
108     """
109     internal
110     {vm-type}_{vm-type_index}_int_{network-role}_vmi_{vmi_index}
111             _IP_{index}
112     {vm-type}_{vm-type_index}_int_{network-role}_vmi_{vmi_index}
113             _v6_IP_{index}
114     """
115     run_test(
116         yaml_file,
117         regex_names=("internal"),
118         network_flavor=ContrailV2InstanceIpProcessor.network_flavor_internal,
119     )