Add a script to validate templates

This adds a new script that can walk through a template directory and
call heat template-validate on them. It handles environment files by
expecting $template_env.ext, so it'll need renaming for the 2 templates
that we have needing that. It also needs #1298450 fixed. The goal is to
be able to use this script in a future gate.

Change-Id: I4246d494de9a3a56c3b334ba20ad06186ccaefd6
This commit is contained in:
Thomas Herve 2014-03-27 21:35:59 +01:00
parent e564ec5a9e
commit 745b0dd5a8
1 changed files with 40 additions and 0 deletions

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:])