diff --git a/aodncore/bin/__init__.py b/aodncore/bin/__init__.py new file mode 100644 index 00000000..e69de29b 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/aodncore/testlib/__init__.py b/aodncore/testlib/__init__.py index 83b1f96b..cbb1a48e 100644 --- a/aodncore/testlib/__init__.py +++ b/aodncore/testlib/__init__.py @@ -5,7 +5,7 @@ from .dummyhandler import DummyHandler from .handlertest import HandlerTestCase from .testutil import (NullStorageBroker, dest_path_testing, get_nonexistent_path, get_test_config, make_test_file, - make_zip) + make_zip, TESTLIB_CONF_DIR) __all__ = [ 'BaseTestCase', @@ -16,5 +16,6 @@ 'get_nonexistent_path', 'get_test_config', 'make_test_file', - 'make_zip' + 'make_zip', + 'TESTLIB_CONF_DIR' ] diff --git a/aodncore/testlib/testutil.py b/aodncore/testlib/testutil.py index 9994188a..da89f9d1 100644 --- a/aodncore/testlib/testutil.py +++ b/aodncore/testlib/testutil.py @@ -21,7 +21,8 @@ 'make_test_file', 'make_zip', 'get_test_config', - 'load_runtime_patched_pipeline_config_file' + 'load_runtime_patched_pipeline_config_file', + 'TESTLIB_CONF_DIR' ] GLOBAL_TEST_BASE = os.path.dirname(os.path.dirname(__file__)) diff --git a/setup.py b/setup.py index 61fa01dc..a3e5f651 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, diff --git a/test_aodncore/test_bin/__init__.py b/test_aodncore/test_bin/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test_aodncore/test_bin/test_bin.py b/test_aodncore/test_bin/test_bin.py new file mode 100644 index 00000000..032ad026 --- /dev/null +++ b/test_aodncore/test_bin/test_bin.py @@ -0,0 +1,17 @@ +import os + +from aodncore.testlib import BaseTestCase, TESTLIB_CONF_DIR +from aodncore.bin import configvalidate + +TEST_PIPELINE_CONFIG_FILE = os.path.join(TESTLIB_CONF_DIR, 'pipeline.conf') +TEST_WATCHES_CONFIG_FILE = os.path.join(TESTLIB_CONF_DIR, 'watches.conf') + + +class TestConfigValidate(BaseTestCase): + def test_valid_pipeline_config(self): + retval = configvalidate.validate_config_file(TEST_PIPELINE_CONFIG_FILE) + self.assertEqual(retval, 0) + + def test_invalid_pipeline_config(self): + retval = configvalidate.validate_config_file(TEST_WATCHES_CONFIG_FILE) + self.assertEqual(retval, 1)