template-validate is now updated to validate the template by using stack create validation path, which causes some of the existing templates in this repository to fail. so this patch is added to mark them as invalid and skip them as part of template validation. It was failing becuase of circular reference among the resources in these invalid templates. depends-on: I15891196be94d1e100869edeba0a7ef557edb36a Change-Id: I6a003f35495bb43e0ca2a824eb9e503c4059c37a
52 lines
1.4 KiB
Python
Executable File
52 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import os
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
EXCLUDED_DIRS = ('contrib', 'elements', 'invalid')
|
|
|
|
|
|
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 excluded in EXCLUDED_DIRS:
|
|
if excluded in dirs:
|
|
dirs.remove(excluded)
|
|
for name in files:
|
|
if name.endswith((".yaml", ".template")):
|
|
got_error = validate(root, name) or got_error
|
|
sys.exit(int(got_error))
|
|
|
|
|
|
def validate(base, name):
|
|
basename, ext = os.path.splitext(name)
|
|
if basename.endswith("_env"):
|
|
return False
|
|
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:
|
|
subprocess.check_output(args, stderr=subprocess.STDOUT)
|
|
except subprocess.CalledProcessError as e:
|
|
print "Got error validating %sputt%s , %s" % (base, name, e.output)
|
|
if re.search('ERROR: Service (\S+) does not have required endpoint in'
|
|
' service catalog for the resource type (\S+)', e.output):
|
|
return False
|
|
else:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.argv[1:])
|