From a0d94fd5e1ad4d1a35563285fc983a0bd46c886b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20=C5=A0imon?= Date: Tue, 10 Dec 2019 14:56:30 +0100 Subject: [PATCH 1/2] add json validation for validation in common-templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit this validation checks if validation is in correct json format Signed-off-by: Karel Šimon --- travis_ci/check-validations.py | 45 ++++++++++++++++++++++++++++++++++ travis_ci/test_syntax.sh | 2 ++ 2 files changed, 47 insertions(+) create mode 100644 travis_ci/check-validations.py 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 From 143af34d18ce30492828282e212c531cd696b358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20=C5=A0imon?= Date: Tue, 14 Jan 2020 10:21:17 +0100 Subject: [PATCH 2/2] add missing pyyaml library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Karel Šimon --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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