Skip to content

Commit

Permalink
add json validation for validation in common-templates
Browse files Browse the repository at this point in the history
this validation checks if validation is in correct json format

Signed-off-by: Karel Šimon <[email protected]>
  • Loading branch information
ksimon1 committed Jan 14, 2020
1 parent 9b015ff commit a0d94fd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
45 changes: 45 additions & 0 deletions travis_ci/check-validations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#! python

import logging
import os
import os.path
import yaml
import sys
import json

def checkValidations(path):
templates = [f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
for template in templates:
with open(path + "/" + template, 'r') as stream:
try:
template = yaml.safe_load(stream)

if template == None:
logging.info("Empty template file: %s", template)
continue

logging.info("Checking " + template["metadata"]["name"])

try:
json.loads(template["metadata"]["annotations"]["validations"])
except Exception as e:
logging.info("Validation is not json")
raise e

except yaml.YAMLError as exc:
raise exc



if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
logging.info("Running syntax check for validations in common templates")

try:
checkValidations("dist/templates")
except Exception as e:
logging.error(e)
sys.exit(1)



2 changes: 2 additions & 0 deletions travis_ci/test_syntax.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ templates=("dist/templates/*.yaml")
for template in $templates; do
oc process -f "$template" NAME=test PVCNAME=test || exit 1;
done

python3 travis_ci/check-validations.py

0 comments on commit a0d94fd

Please sign in to comment.