How to use the kas.includehandler.LoadConfigException function in kas

To help you get started, we’ve selected a few kas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github siemens / kas / tests / test_includehandler.py View on Github external
def test_err_header_invalid_type(self):
        exception = includehandler.LoadConfigException
        testvector = [
            ('header:', exception),
            ('header: 1', exception),
            ('header: a', exception),
            ('header: []', exception),
        ]

        self.util_exception_content(testvector)
github siemens / kas / kas / includehandler.py View on Github external
def load_config(filename):
    """
        Load the configuration file and test if version is supported.
    """
    (_, ext) = os.path.splitext(filename)
    config = None
    if ext == '.json':
        import json
        with open(filename, 'rb') as fds:
            config = json.load(fds)
    elif ext == '.yml':
        import yaml
        with open(filename, 'rb') as fds:
            config = yaml.safe_load(fds)
    else:
        raise LoadConfigException('Config file extension not recognized',
                                  filename)

    validator = Draft4Validator(CONFIGSCHEMA)
    validation_error = False

    for error in validator.iter_errors(config):
        validation_error = True
        logging.error('Config file validation Error:\n%s', error)

    if validation_error:
        raise LoadConfigException('Error(s) occured while validating the '
                                  'config file', filename)

    try:
        version_value = int(config['header']['version'])
    except ValueError:
github siemens / kas / kas / includehandler.py View on Github external
if validation_error:
        raise LoadConfigException('Error(s) occured while validating the '
                                  'config file', filename)

    try:
        version_value = int(config['header']['version'])
    except ValueError:
        # Be compatible: version string '0.10' is equivalent to file version 1
        # This check is already done in the config schema so here just set the
        # right version
        version_value = 1

    if version_value < __compatible_file_version__ or \
       version_value > __file_version__:
        raise LoadConfigException('This version of kas is compatible with '
                                  'version {} to {}, file has version {}'
                                  .format(__compatible_file_version__,
                                          __file_version__, version_value),
                                  filename)

    return config
github siemens / kas / kas / includehandler.py View on Github external
import yaml
        with open(filename, 'rb') as fds:
            config = yaml.safe_load(fds)
    else:
        raise LoadConfigException('Config file extension not recognized',
                                  filename)

    validator = Draft4Validator(CONFIGSCHEMA)
    validation_error = False

    for error in validator.iter_errors(config):
        validation_error = True
        logging.error('Config file validation Error:\n%s', error)

    if validation_error:
        raise LoadConfigException('Error(s) occured while validating the '
                                  'config file', filename)

    try:
        version_value = int(config['header']['version'])
    except ValueError:
        # Be compatible: version string '0.10' is equivalent to file version 1
        # This check is already done in the config schema so here just set the
        # right version
        version_value = 1

    if version_value < __compatible_file_version__ or \
       version_value > __file_version__:
        raise LoadConfigException('This version of kas is compatible with '
                                  'version {} to {}, file has version {}'
                                  .format(__compatible_file_version__,
                                          __file_version__, version_value),