コード例 #1
0
ファイル: validation.py プロジェクト: optiflows/nyuki
def validate(template):
    """
    Validate a template dict and aggregate all errors that could occur.
    Return a tempplate object or raise a ValidationError
    """
    # Task name validation
    errors = list()
    for task in template.tasks:
        try:
            TaskRegistry.get(task.name)
        except UnknownTaskName:
            errors.append(task.name)
    if errors:
        log.debug("unknown tasks: %s", errors)
        raise TemplateError(key=ErrorInfo.UNKNOWN_TASK, details=errors)

    # DAG semantic validation
    try:
        template.validate()
    except WorkflowRootTaskError as exc:
        log.debug("workflow validation error: %s", exc)
        raise TemplateError(key=ErrorInfo.INVALID_GRAPH, message="Workflow validation error: {}".format(exc)) from exc

    # Task config validation
    errors = list()
    tasks = template.as_dict().get("tasks", [])
    for task in tasks:
        err = validate_task(task, tasks)
        if err:
            errors.append(err)
    if errors:
        raise TemplateError(key=ErrorInfo.INVALID_TASK, details=errors)

    return template
コード例 #2
0
ファイル: validation.py プロジェクト: optiflows/nyuki
def validate_task(task, tasks=None):
    """
    Validate the jsonschema configuration of a task
    """
    name = task["name"]
    config = task.get("config", {})
    schema = getattr(TaskRegistry.get(name)[0], "SCHEMA", {})
    format_checker = getattr(TaskRegistry.get(name)[0], "FORMAT_CHECKER", None)
    try:
        validate_schema(config, schema, format_checker=format_checker)
    except ValidationError as exc:
        return TemplateError.format_details(exc, task)
コード例 #3
0
def validate_task(task, tasks=None):
    """
    Validate the jsonschema configuration of a task
    """
    name = task['name']
    config = task.get('config', {})
    schema = getattr(TaskRegistry.get(name)[0], 'SCHEMA', {})
    format_checker = getattr(TaskRegistry.get(name)[0], 'FORMAT_CHECKER', None)
    try:
        validate_schema(config, schema, format_checker=format_checker)
    except ValidationError as exc:
        return TemplateError.format_details(exc, task)
コード例 #4
0
def validate(template):
    """
    Validate a template dict and aggregate all errors that could occur.
    Return a tempplate object or raise a ValidationError
    """
    # Task name validation
    errors = list()
    for task in template.tasks:
        try:
            TaskRegistry.get(task.name)
        except UnknownTaskName:
            errors.append(task.name)
    if errors:
        log.debug('unknown tasks: %s', errors)
        raise TemplateError(key=ErrorInfo.UNKNOWN_TASK, details=errors)

    # DAG semantic validation
    try:
        template.validate()
    except WorkflowRootTaskError as exc:
        log.debug('workflow validation error: %s', exc)
        raise TemplateError(
            key=ErrorInfo.INVALID_GRAPH,
            message='Workflow validation error: {}'.format(exc)) from exc

    # Task config validation
    errors = list()
    tasks = template.as_dict().get('tasks', [])
    for task in tasks:
        err = validate_task(task, tasks)
        if err:
            errors.append(err)
    if errors:
        raise TemplateError(key=ErrorInfo.INVALID_TASK, details=errors)

    return template