aboutsummaryrefslogtreecommitdiff
path: root/tools/validate-json.py
diff options
context:
space:
mode:
authorLars Kellogg-Stedman <lars@redhat.com>2014-10-14 12:17:47 -0400
committerLars Kellogg-Stedman <lars@redhat.com>2014-10-14 15:21:22 -0400
commitbfbf1b8c9b3a0abba86474aeb72b950142723d73 (patch)
tree6dd25e33a223a6f9011375b01a38302fe83e1968 /tools/validate-json.py
parent20e88776bc9b85b2a3a0f7a86004f6b04520e9a8 (diff)
downloadkolla-bfbf1b8c9b3a0abba86474aeb72b950142723d73.tar.gz
kolla-bfbf1b8c9b3a0abba86474aeb72b950142723d73.zip
add better validation checks (part 1)
This patch adds a script for validating YAML files, and replaces the existing JSON checks with one largely identical to the YAML check. This also provides a script that can be installed as a pre-commit hook that will perform this checks when you commit changes. You can install the hook by running tools/pre-commit-hook --install. Change-Id: Ib4742a9db062362cfa61d669c691151bc1ca376c
Diffstat (limited to 'tools/validate-json.py')
-rwxr-xr-xtools/validate-json.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tools/validate-json.py b/tools/validate-json.py
new file mode 100755
index 000000000..d7e1cd873
--- /dev/null
+++ b/tools/validate-json.py
@@ -0,0 +1,33 @@
+#!/usr/bin/python
+
+import os
+import sys
+import argparse
+import json
+import logging
+
+def parse_args():
+ p = argparse.ArgumentParser()
+ p.add_argument('input', nargs='*')
+ return p.parse_args()
+
+def main():
+ args = parse_args()
+ logging.basicConfig()
+ res = 0
+
+ for filename in args.input:
+ with open(filename) as fd:
+ try:
+ data = json.load(fd)
+ except ValueError as error:
+ res = 1
+ logging.error('%s failed validation: %s',
+ filename, error)
+
+ sys.exit(res)
+
+if __name__ == '__main__':
+ main()
+
+