diff --git a/.travis.yml b/.travis.yml index a0fa4bdd..ffd75b2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/travis_ci/check-validations.py b/travis_ci/check-validations.py new file mode 100644 index 00000000..8ac7d384 --- /dev/null +++ b/travis_ci/check-validations.py @@ -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) + + + diff --git a/travis_ci/test_syntax.sh b/travis_ci/test_syntax.sh index 49aa5d19..fbbd40c1 100755 --- a/travis_ci/test_syntax.sh +++ b/travis_ci/test_syntax.sh @@ -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