2 # ============LICENSE_START====================================================
3 # org.onap.vvp/validation-scripts
4 # ===================================================================
5 # Copyright © 2020 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.
21 # Unless otherwise specified, all documentation contained herein is licensed
22 # under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 # you may not use this documentation except in compliance with the License.
24 # You may obtain a copy of the License at
26 # https://creativecommons.org/licenses/by/4.0/
28 # Unless required by applicable law or agreed to in writing, documentation
29 # distributed under the License is distributed on an "AS IS" BASIS,
30 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 # See the License for the specific language governing permissions and
32 # limitations under the License.
34 # ============LICENSE_END============================================
36 from os import listdir
39 from pathlib import Path
43 from .helpers import check_basename_ending
44 from .helpers import validates
47 RE_BASE = re.compile(r"(^base$)|(^base_)|(_base_)|(_base$)")
50 def list_filenames(template_dir):
53 for f in listdir(template_dir)
54 if path.isfile(path.join(template_dir, f))
55 and path.splitext(f)[-1] in [".yaml", ".yml"]
59 @validates("R-81339", "R-87247", "R-76057")
60 def test_template_names_valid_characters(template_dir):
61 filenames = list_filenames(template_dir)
65 if not stem.replace("_", "").isalnum():
68 "The following Heat template names include characters other than "
69 "alphanumerics and underscores: {}"
70 ).format(", ".join(errors))
73 @validates("R-37028", "R-87485", "R-81339", "R-87247", "R-76057")
74 def test_base_template_names(template_dir):
76 Check all base templates have a filename that includes "_base_".
78 filenames = list_filenames(template_dir)
80 if not filenames and listdir(template_dir):
81 pytest.skip("Nested directory detected. Let that test fail instead.")
84 for filename in filenames:
85 basename = path.splitext(filename)[0]
87 # volume templates are tied to their parent naming wise
88 if check_basename_ending("volume", basename):
91 if RE_BASE.search(basename.lower()):
92 base_modules.append(filename)
96 "No base module detected in the following files "
97 "from the template directory: {}"
98 ).format(", ".join(filenames))
99 elif len(base_modules) > 1:
101 "Multiple base modules detected in the template "
102 "directory, but only one is allowed: {}"
103 ).format(", ".join(base_modules))
107 assert len(base_modules) == 1, msg