diff --git a/aodncore/bin/configvalidate.py b/aodncore/bin/configvalidate.py new file mode 100755 index 00000000..81c1f344 --- /dev/null +++ b/aodncore/bin/configvalidate.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +"""Script to test the validity of pipeline configuration, + +""" +import argparse +import os +from jsonschema.exceptions import ValidationError +from aodncore.pipeline.configlib import load_pipeline_config, validate_pipeline_config + + +def validate_config_file(pipeline_conf_file): + try: + print("validating pipeline config file '{path}'...".format(path=pipeline_conf_file)) + pipeline_config = load_pipeline_config(pipeline_conf_file) + validate_pipeline_config(pipeline_config) + except ValidationError as e: + print("VALIDATION FAILED{nl}{nl}{e}".format(e=str(e), nl=os.linesep)) + return 1 + else: + print('VALIDATION SUCCEEDED') + return 0 + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('path') + args = parser.parse_args() + + exit(validate_config_file(args.path)) diff --git a/aodncore/pipeline/configlib.py b/aodncore/pipeline/configlib.py index 12c33d2c..910a51ec 100644 --- a/aodncore/pipeline/configlib.py +++ b/aodncore/pipeline/configlib.py @@ -21,7 +21,8 @@ 'load_pipeline_config', 'load_trigger_config', 'load_watch_config', - 'validate_lazyconfigmanager' + 'validate_lazyconfigmanager', + 'validate_pipeline_config' ] DEFAULT_CONFIG_FILE = '/mnt/ebs/pipeline/etc/pipeline.conf' diff --git a/setup.py b/setup.py index 5a0dbe8a..d6a8ea5d 100644 --- a/setup.py +++ b/setup.py @@ -36,7 +36,10 @@ PACKAGE_EXCLUDES = ['test_aodncore.*', 'test_aodncore'] PACKAGE_NAME = 'aodncore' -PACKAGE_SCRIPTS = ['aodncore/bin/drawmachine.py', 'aodncore/pipeline/watchservice.py'] +PACKAGE_SCRIPTS = [ + 'aodncore/bin/drawmachine.py', + 'aodncore/bin/configvalidate.py', + 'aodncore/pipeline/watchservice.py'] setup( name=PACKAGE_NAME,