Merge "Add a script to validate templates"
This commit is contained in:
40
tools/validate-templates
Executable file
40
tools/validate-templates
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def main(args):
|
||||
if len(args) != 1:
|
||||
raise SystemExit("Takes one argument, the path to the templates")
|
||||
|
||||
path = args[0]
|
||||
got_error = False
|
||||
for root, dirs, files in os.walk(path):
|
||||
for name in files:
|
||||
if name.endswith((".yaml", ".template")):
|
||||
got_error = validate(root, name)
|
||||
sys.exit(int(got_error))
|
||||
|
||||
|
||||
def validate(base, name):
|
||||
basename, ext = os.path.splitext(name)
|
||||
if basename.endswith("_env"):
|
||||
return
|
||||
args = ["heat", "template-validate", "-f", os.path.join(base, name)]
|
||||
base_env = "%s_env%s" % (basename, ext)
|
||||
env = os.path.join(base, base_env)
|
||||
if os.path.exists(env):
|
||||
args.extend(["-e", env])
|
||||
try:
|
||||
output = subprocess.check_output(args)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print "Got error validating %s" % name
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1:])
|
||||
Reference in New Issue
Block a user