Merge "Add a script to validate templates"

This commit is contained in:
Jenkins
2014-03-27 21:00:28 +00:00
committed by Gerrit Code Review

40
tools/validate-templates Executable file
View 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:])