Exemple #1
0
def _import_error(error_dict, error=None):
    """Attempts to apply the given error configuration to the system.

    Note that proper model locking must be performed before calling this method.

    :param error_dict: A dictionary of error configuration changes to import.
    :type error_dict: dict
    :param error: The existing error model to update if applicable.
    :type error: :class:`error.models.Error`
    :returns: A list of warnings discovered during import.
    :rtype: list[:class:`port.schema.ValidationWarning`]

    :raises :class:`port.schema.InvalidConfiguration`: If any part of the configuration violates the specification.
    """
    warnings = []

    # Parse the JSON content and merge the fields into a model
    error_serializer = serializers.ConfigurationErrorSerializer(error, data=error_dict)
    if not error_serializer.is_valid():
        raise InvalidConfiguration('Invalid error schema: %s -> %s' % (error_dict.get('name'), error_serializer.errors))
    result = error_serializer.validated_data

    # Importing system-level errors is not allowed
    if result.get('category') == 'SYSTEM' or (error and error.category == 'SYSTEM'):
        raise InvalidConfiguration('System errors cannot be imported: %s' % result.get('name'))

    error_serializer.save()
    return warnings
Exemple #2
0
def export_config(recipe_types=None, job_types=None, errors=None):
    recipe_types = recipe_types or []
    job_types = job_types or []
    errors = errors or []

    export_config = {
        'version':
        '1.0',
        'recipe_types': [
            serializers.ConfigurationRecipeTypeSerializer(r).data
            for r in recipe_types
        ],
        'job_types': [
            serializers.ConfigurationJobTypeSerializer(j).data
            for j in job_types
        ],
        'errors':
        [serializers.ConfigurationErrorSerializer(e).data for e in errors],
    }
    return Configuration(export_config)