Enforce black code format via pre-commit hook
[vvp/validation-scripts.git] / ice_validator / tests / test_fixed_ips_include_vm_type_network_role.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 #
39
40 import re
41
42 from .helpers import validates
43 from .utils.ports import check_parameter_format
44 from tests.structures import NeutronPortProcessor
45
46
47 RE_EXTERNAL_PARAM_FIP = re.compile(  # match pattern
48     r"(?P<vm_type>.+)_(?P<network_role>.+?)(_v6)?_ip_(?P<ip_index>.+)$"
49 )
50
51 RE_EXTERNAL_PARAM_FIPS = re.compile(  # match pattern
52     r"(?P<vm_type>.+)_(?P<network_role>.+?)(_v6)?_ips$"
53 )
54
55 RE_INTERNAL_PARAM_FIP = re.compile(  # match pattern
56     r"(?P<vm_type>.+)_int_(?P<network_role>.+?)(_v6)?_ip_(?P<ip_index>.+)$"
57 )
58
59 RE_INTERNAL_PARAM_FIPS = re.compile(  # match pattern
60     r"(?P<vm_type>.+)_int_(?P<network_role>.+?)(_v6)?_ips$"
61 )
62
63 fip_regx_dict = {
64     "external": {
65         "string": {
66             "readable": "{vm-type}_{network-role}_ip_{ip-index} or {vm-type}_{network-role}_v6_ip_{ip-index}",
67             "machine": RE_EXTERNAL_PARAM_FIP,
68         },
69         "comma_delimited_list": {
70             "readable": "{vm-type}_{network-role}_ips or {vm-type}_{network-role}_v6_ips",
71             "machine": RE_EXTERNAL_PARAM_FIPS,
72         },
73     },
74     "internal": {
75         "string": {
76             "readable": "{vm-type}_int_{network-role}_ip_{ip-index} or {vm-type}_int_{network-role}_v6_ip_{ip-index}",
77             "machine": RE_INTERNAL_PARAM_FIP,
78         },
79         "comma_delimited_list": {
80             "readable": "{vm-type}_int_{network-role}_ips or {vm-type}_int_{network-role}_v6_ips",
81             "machine": RE_INTERNAL_PARAM_FIPS,
82         },
83     },
84     "parameter_to_resource_comparisons": ["vm_type", "network_role"],
85 }
86
87
88 @validates("R-40971", "R-35735", "R-23503", "R-71577", "R-04697", "R-34037")
89 def test_external_fip_format(yaml_file):
90     check_parameter_format(
91         yaml_file,
92         fip_regx_dict,
93         "external",
94         NeutronPortProcessor,
95         "fixed_ips",
96         "ip_address",
97     )
98
99
100 @validates("R-27818", "R-29765", "R-85235", "R-78380", "R-34037")
101 def test_internal_fip_format(yaml_file):
102     check_parameter_format(
103         yaml_file,
104         fip_regx_dict,
105         "internal",
106         NeutronPortProcessor,
107         "fixed_ips",
108         "ip_address",
109     )