Exemplo n.º 1
0
def check_design(config):
    kinds = ['Docker', 'Genesis', 'HostSystem', 'Kubelet', 'KubernetesNetwork']
    validation_msg = ValidationMessage()
    for kind in kinds:
        count = 0
        schema = None
        name = None
        for doc in config.documents:
            schema = doc.get('schema', None)
            if not schema:
                msg = '"schema" is a required document key.'
                exc = exceptions.ValidationException(msg)
                validation_msg.add_error_message(str(exc), name=exc.title)
                return validation_msg
            name = schema.split('/')[1]
            if name == kind:
                count += 1
        if count != 1:
            msg = ('There are {0} {1} documents. However, there should be one.'
                   ).format(count, kind)
            exc = exceptions.ValidationException(msg)
            validation_msg.add_error_message(str(exc),
                                             name=exc.title,
                                             schema=schema,
                                             doc_name=kind)
    return validation_msg
Exemplo n.º 2
0
def check_design(config):
    """Check that each document type has the correct cardinality."""

    expected_count = {
        'Docker': 1,
        'Genesis': 1,
        'HostSystem': 1,
        'Kubelet': 1,
        'KubernetesNetwork': 1,
    }

    counts = {}
    exception_list = []

    for k in expected_count.keys():
        counts[k] = 0

    for doc in config.documents:
        schema = doc.get('schema', None)
        if not schema:
            msg = '"schema" is a required document key.'
            exception_list.append(exceptions.ValidationException(msg))
            continue
        name = schema.split('/')[1]
        if name in counts:
            counts[name] += 1

    for kind, cnt in counts.items():
        if cnt != 1:
            msg = ('There are {0} {1} documents. However, there should be one.'
                   ).format(cnt, kind)
            exception_list.append(exceptions.ValidationException(msg))
    return exception_list
Exemplo n.º 3
0
def check_design(config):
    kinds = ['Docker', 'HostSystem', 'Kubelet', 'KubernetesNetwork']
    for kind in kinds:
        count = 0
        for doc in config.documents:
            schema = doc.get('schema', None)
            if not schema:
                raise exceptions.ValidationException(
                    '"schema" is a required document key.')
            name = schema.split('/')[1]
            if name == kind:
                count += 1
        if count != 1:
            raise exceptions.ValidationException()
Exemplo n.º 4
0
def check_design(config):
    kinds = ['Docker', 'HostSystem', 'Kubelet', 'KubernetesNetwork']
    result = copy.deepcopy(result_template)
    for kind in kinds:
        count = 0
        for doc in config.documents:
            schema = doc.get('schema', None)
            if not schema:
                result['msg'].append(
                    str(
                        exceptions.ValidationException(
                            '"schema" is a required document key.')))
                result['err_count'] += 1
                return result
            name = schema.split('/')[1]
            if name == kind:
                count += 1
        if count != 1:
            msg = ('There are {0} {1} documents. However, there should be one.'
                   ).format(count, kind)
            result['msg'].append(
                str(exceptions.ValidationException(description=msg)))
            result['err_count'] += 1
    return result
Exemplo n.º 5
0
def check_schema(document):
    if type(document) != dict:
        LOG.error('Non-dictionary document passed to schema validation.')
        return

    schema_name = document.get('schema', '<missing>')

    LOG.debug('Validating schema for schema=%s metadata.name=%s', schema_name,
              document.get('metadata', {}).get('name', '<missing>'))

    if schema_name in SCHEMAS:
        try:
            jsonschema.validate(document.get('data'), SCHEMAS[schema_name])
        except jsonschema.ValidationError as e:
            raise exceptions.ValidationException(str(e))
    else:
        LOG.warning('Skipping validation for unknown schema: %s', schema_name)
Exemplo n.º 6
0
def check_schema(document, schemas=None):
    if not isinstance(document, dict):
        msg = 'Non-dictionary document passed to schema validation.'
        LOG.error(msg)
        return

    schema_name = document.get('schema', '<missing>')

    LOG.debug('Validating schema for schema=%s metadata.name=%s', schema_name,
              document.get('metadata', {}).get('name', '<missing>'))

    schema_set = SCHEMAS if schemas is None else schemas

    if schema_name in schema_set:
        try:
            jsonschema.validate(document.get('data'), schema_set[schema_name])
        except jsonschema.ValidationError as e:
            raise exceptions.ValidationException(str(e))
    else:
        LOG.warning('Skipping validation for unknown schema: %s', schema_name)