Skip to content

Commit

Permalink
Merge pull request #119 from ksimon1/check-validations
Browse files Browse the repository at this point in the history
add json validation for validation in common-templates
  • Loading branch information
ksimon1 authored Jan 14, 2020
2 parents 8eca33f + 143af34 commit 7b50a3b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ addons:
- jq
- ansible
- python-gobject
python-six
- python-six
- python3-pip
- libosinfo-1.0
- gir1.2-libosinfo-1.0
- intltool
before_script:
- pip install PyYAML
- sudo mount --make-rshared /
- bash -x ci/ci/extra/get-kubevirt-releases
- bash -x ci/prepare-host $CPLATFORM
Expand Down
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 7b50a3b

Please sign in to comment.