2 # ============LICENSE_START=======================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2019 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============================================
39 from tests.helpers import validates
40 from tests.utils.nested_files import get_nested_files
41 from tests.structures import Heat, Resource
44 def non_nested_files(filenames):
45 nested_files = get_nested_files(filenames)
46 return set(filenames).difference(set(nested_files))
49 @validates("R-589037")
50 def test_detected_volume_module_follows_naming_convention(template_dir):
51 all_files = [os.path.join(template_dir, f) for f in os.listdir(template_dir)]
52 yaml_files = [f for f in all_files if f.endswith(".yaml") or f.endswith(".yml")]
54 for yaml_file in non_nested_files(yaml_files):
55 heat = Heat(filepath=yaml_file)
56 if not heat.resources:
58 base_dir, filename = os.path.split(yaml_file)
59 resources = heat.get_all_resources(base_dir)
62 for r_id, r_data in resources.items()
63 if not Resource(r_id, r_data).is_nested()
67 for r_id, r_data in resources.items()
68 if Resource(r_id, r_data).resource_type == "OS::Cinder::Volume"
70 non_volume_ids = non_nested_ids.difference(volume_ids)
72 continue # Not a volume module
73 base_name, ext = os.path.splitext(filename)
74 if not base_name.endswith("_volume") or ext not in (".yaml", ".yml"):
75 errors.append(yaml_file)
77 "Volume modules detected, but they do not follow the expected "
78 + " naming convention {{module_name}}_volume.[yaml|yml]: {}"
79 ).format(", ".join(errors))
80 assert not errors, msg