From cad73b5646051c284822146a817c7072cd2aedc9 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Thu, 6 Apr 2017 11:54:26 -0700 Subject: [PATCH] Add config validation for default_data It is a little difficult to set up default_data.json for users, and we already have the corresponding schema in the code. JSON-Schema outputs useful error message when users misconfigures some items. So this patch makes the schema validation enabled for default_data. Change-Id: Id0efae913c202a30476d73a3821711c5250fcfee --- requirements.txt | 1 + stackalytics/processor/main.py | 8 ++++++++ test-requirements.txt | 1 - 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index f83c89d00..506911691 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ pbr>=2.0.0 # Apache-2.0 Babel>=2.3.4 # BSD Flask!=0.11,<1.0,>=0.10 # BSD iso8601>=0.1.11 # MIT +jsonschema>=2.0.0,<3.0.0,!=2.5.0 # MIT oslo.config>=3.22.0 # Apache-2.0 oslo.i18n>=2.1.0 # Apache-2.0 oslo.log>=3.22.0 # Apache-2.0 diff --git a/stackalytics/processor/main.py b/stackalytics/processor/main.py index 60b9a5505..50b042ad7 100644 --- a/stackalytics/processor/main.py +++ b/stackalytics/processor/main.py @@ -15,6 +15,7 @@ import itertools +import jsonschema from oslo_config import cfg from oslo_log import log as logging import psutil @@ -32,6 +33,7 @@ from stackalytics.processor import mps from stackalytics.processor import rcs from stackalytics.processor import record_processor from stackalytics.processor import runtime_storage +from stackalytics.processor import schema from stackalytics.processor import utils from stackalytics.processor import vcs from stackalytics.processor import zanata @@ -316,6 +318,12 @@ def main(): LOG.critical('Unable to load default data') return not 0 + try: + jsonschema.validate(default_data, schema.default_data) + except jsonschema.ValidationError as e: + LOG.critical('The default data is invalid: %s' % e) + return not 0 + default_data_processor.process(runtime_storage_inst, default_data, CONF.driverlog_data_uri) diff --git a/test-requirements.txt b/test-requirements.txt index 2d812958a..0a075aac5 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,7 +6,6 @@ hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 coverage>=4.0 # Apache-2.0 fixtures>=3.0.0 # Apache-2.0/BSD -jsonschema!=2.5.0,<3.0.0,>=2.0.0 # MIT mock>=2.0 # BSD python-subunit>=0.0.18 # Apache-2.0/BSD sphinx>=1.5.1 # BSD