Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configvalidate.py script to allow config validation during deploy… #226

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added aodncore/bin/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions aodncore/bin/configvalidate.py
Original file line number Diff line number Diff line change
@@ -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))
3 changes: 2 additions & 1 deletion aodncore/pipeline/configlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 3 additions & 2 deletions aodncore/testlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -16,5 +16,6 @@
'get_nonexistent_path',
'get_test_config',
'make_test_file',
'make_zip'
'make_zip',
'TESTLIB_CONF_DIR'
]
3 changes: 2 additions & 1 deletion aodncore/testlib/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Empty file.
17 changes: 17 additions & 0 deletions test_aodncore/test_bin/test_bin.py
Original file line number Diff line number Diff line change
@@ -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)