2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 # ===================================================================
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
13 # http://www.apache.org/licenses/LICENSE-2.0
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.
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
28 # https://creativecommons.org/licenses/by/4.0/
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.
36 # ============LICENSE_END============================================
42 {vm-type}_{vm-type_index}_{network-role}_port_{port-index}:
43 type: OS::Neutron::Port
45 network: { get_param: ...}
46 fixed_ips: [ { "ipaddress": { get_param: ... } } ]
47 binding:vnic_type: direct #only SR-IOV ports, not OVS ports
49 vlan_filter: { get_param: ... }, #all NC ports
50 public_vlans: { get_param: ... }, #all NC ports
51 private_vlans: { get_param: ... },#all NC ports
52 guest_vlans: { get_param: ... }, #SR-IOV Trunk Port only
53 vlan_mirror: { get_param: ... }, #SRIOV Trunk Port
54 # Receiving Mirrored Traffic only
55 ATT_FABRIC_CONFIGURATION_REQUIRED: true #all NC ports
58 port_type: SR-IOV_Trunk #SR-IOV Trunk Port
59 port_type: SR-IOV_Non_Trunk #SR-IOV Non Trunk Port
60 port_type: OVS #OVS Port
61 port_type: SR-IOV_Mirrored_Trunk #SR-IOV Trunk Port
62 # Receiving Mirrored Traffic
68 from .structures import Heat
69 from .helpers import validates
74 def case_mismatch(vm_type, param):
75 """Return True if vm_type matches a portion of param in a case
76 insensitive search, but does not equal that portion;
77 return False otherwise.
78 The "portions" of param are delimited by "_".
80 re_portion = re.compile(
81 "(^(%(x)s)_)|(_(%(x)s)_)|(_(%(x)s)$)" % dict(x=vm_type), re.IGNORECASE
83 found = re_portion.search(param)
85 param_vm_type = [x for x in found.groups()[1::2] if x][0]
86 return param_vm_type != vm_type
91 # pylint: disable=invalid-name
95 def test_vm_type_case(yaml_file):
97 A VNF's Heat Orchestration Template's use of ``{vm-type}`` in all Resource
98 property parameter names **MUST** be the same case.
100 heat = Heat(filepath=yaml_file)
101 resources = heat.resources
102 bad = collections.defaultdict(list)
103 for rid, resource in resources.items():
104 vm_type = heat.get_vm_type(rid, resource=resource)
106 properties = resource.get("properties")
107 if isinstance(properties, dict):
108 for prop, dic in properties.items():
109 param = heat.nested_get(dic, "get_param")
110 if isinstance(param, list):
112 if isinstance(param, str) and case_mismatch(vm_type, param):
113 bad[(rid, vm_type)].append((prop, param))
115 raise AssertionError(
116 "vm-type/parameter case mis-match %s"
119 "resource: %s vm-type: %s %s"
120 % (k[0], k[1], ", ".join("%s: %s" % i for i in v))
121 for k, v in bad.items()