Skip to content

Commit 5945281

Browse files
kwilczynskinuclearcat
authored andcommitted
Fix validation for trees within build_configs
Commit c00b656 ("(tests/validator) Improve build_configs verification") added validation of the "tree" and "branch" attributes to the build_configs property. However, if a referenced tree is missing, the validation code will terminate with an error as the variable used is not a dictionary but a string type, and as such, the .get() method cannot be called. Thus, fix which variables are referenced and the order of validation for the "tree" and "branch" attributes to validate their presence within a given tree object first. While at it, update the accompanying code comment. Signed-off-by: Krzysztof Wilczyński <[email protected]>
1 parent c00b656 commit 5945281

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

Diff for: tests/validate_yaml.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,25 @@ def validate_unused_jobs(data):
100100

101101
def validate_build_configs(data):
102102
'''
103-
Each entry in build_configs have a tree parameter
104-
This tree should exist in the trees: section
103+
Each entry in build_configs must have a tree and branch attribute
104+
When referenced, a given tree must exist in the trees: section
105105
'''
106106
build_configs = data.get('build_configs')
107107
trees = data.get('trees')
108108
for entry in build_configs:
109-
if build_configs[entry].get('tree') not in trees.keys():
110-
raise yaml.YAMLError(
111-
f"Tree {entry.get('tree')} not found in trees"
112-
)
113-
# each build config must have fields tree and branch
114-
if not build_configs[entry].get('tree'):
109+
tree = build_configs[entry].get('tree')
110+
if not tree:
115111
raise yaml.YAMLError(
116112
f"Tree not found for build config: {entry}'"
117113
)
118114
if not build_configs[entry].get('branch'):
119115
raise yaml.YAMLError(
120116
f"Branch not found for build config: {entry}'"
121117
)
118+
if not tree in trees.keys():
119+
raise yaml.YAMLError(
120+
f"Tree {tree} not found in trees"
121+
)
122122

123123
def validate_unused_trees(data):
124124
'''

0 commit comments

Comments
 (0)