validation of input parameters through jsonSchemaValidation

Registered by Sheel Rana

I could see in nova and keystone that they are validating input parameters in start of operation itself instead of going ahead and reported error after error occurs.

This is in reference of 4 byte unicode character handling at API layer itseld instead of going to db layer and then reporting error.

We should follow same in cinder as well for better optimized flow of operations with less cpu cycles.

Some nova code taken for example:

##Validation:

    def validate(self, *args, **kwargs):
        try:
            self.validator.validate(*args, **kwargs)
        except jsonschema.ValidationError as ex:
            # NOTE: For whole OpenStack message consistency, this error
            # message has been written as the similar format of WSME.
            if len(ex.path) > 0:
                detail = _("Invalid input for field/attribute %(path)s."
                           " Value: %(value)s. %(message)s") % {
                               'path': ex.path.pop(), 'value': ex.instance,
                               'message': ex.message
                           }
            else:
                detail = ex.message
            raise exception.ValidationError(detail=detail)
        except TypeError as ex:
            # NOTE: If passing non string value to patternProperties parameter,
            # TypeError happens. Here is for catching the TypeError.
            detail = six.text_type(ex)
            raise exception.ValidationError(detail=detail)

##At API layer,
https://github.com/openstack/nova/blob/master/nova/api/openstack/compute/create_backup.py

    @validation.schema(create_backup.create_backup, '2.1')
    def _create_backup(self, req, id, body):
        """Backup a server instance.

https://github.com/openstack/nova/tree/master/nova/api/openstack/compute/schemas

This is just and idea fro now specifically for 4 byte unicode handling at API layer instead of going to database layer.
I need to further analyze different other requirements or use cases for this feature.

Blueprint information

Status:
Started
Approver:
Sean McGinnis
Priority:
Low
Drafter:
Sheel Rana
Direction:
Approved
Assignee:
Dinesh Bhor
Definition:
Approved
Series goal:
Accepted for rocky
Implementation:
Started
Milestone target:
milestone icon rocky-2
Started by
Jay Bryant

Related branches

Sprints

Whiteboard

Gerrit topic: https://review.openstack.org/#q,topic:bp/json-schema-validation,n,z

Addressed by: https://review.openstack.org/507386
    Add json schema validation for V3 API's

Addressed by: https://review.openstack.org/515649
    V3 jsonschema validation: base schema framework

Addressed by: https://review.openstack.org/518457
    V3 jsonschema validation: Attachments

Addressed by: https://review.openstack.org/519643
    V3 jsonschema validation: Group types

Addressed by: https://review.openstack.org/520285
    V3 jsonschema validation: Group type specs

Addressed by: https://review.openstack.org/520561
    V3 jsonschema validation: Volume-types

Addressed by: https://review.openstack.org/520991
    V3 jsonschema validation: snapshots

Addressed by: https://review.openstack.org/524528
    V3 jsonschema validation: Group Snapshots

Addressed by: https://review.openstack.org/525077
    V3 jsonschema validation: Group types

Addressed by: https://review.openstack.org/526606
    V3 jsonschema validation: Volume metadata

Addressed by: https://review.openstack.org/527937
    V2/V3 jsonschema validation: snapshots

Addressed by: https://review.openstack.org/528182
    V3 jsonschema validation: Clusters

Addressed by: https://review.openstack.org/528631
    V2/V3 json schema validation: snapshot manage

Addressed by: https://review.openstack.org/528633
    V3 json schema validation: workers

Addressed by: https://review.openstack.org/530098
    V3 jsonschema validation: Backups

Addressed by: https://review.openstack.org/536237
    V3 jsonschema validation: volume_type_access

Addressed by: https://review.openstack.org/552468
    V3 jsonschema validation: qos-specs

Addressed by: https://review.openstack.org/552858
    V3 jsonschema validation: volume_image_metadata

Addressed by: https://review.openstack.org/553175
    Move json schema validation for V3 API's to Rocky

Addressed by: https://review.openstack.org/553369
    V3 jsonschema validation: snapshot_actions

Addressed by: https://review.openstack.org/554458
    V3 jsonschema validation: types_extra_specs

Addressed by: https://review.openstack.org/555717
    V3 json schema validation: volume manage

Addressed by: https://review.openstack.org/559042
    V3 jsonschema validation: volume actions

Addressed by: https://review.openstack.org/561133
    V3 jsonschema validation: volume_transfer

Addressed by: https://review.openstack.org/561140
    V3 jsonschema validation: volume_type_encryption

Addressed by: https://review.openstack.org/561558
    V3 jsonschema validation: Quotas

Addressed by: https://review.openstack.org/561960
    V3 jsonschema validation: Quota classes

Addressed by: https://review.openstack.org/566525
    V3 jsonschema validation: scheduler_hints

Addressed by: https://review.openstack.org/566530
    V3 jsonschema validation: os-services

Addressed by: https://review.openstack.org/566876
    V3 json schema validation: generic volume groups

Addressed by: https://review.openstack.org/570356
    V3 jsonschema validation: admin_actions

Gerrit topic: https://review.openstack.org/#q,topic:bug/1774155,n,z

Addressed by: https://review.openstack.org/573093
    V3 jsonschema validation: Volumes

Addressed by: https://review.openstack.org/573137
    Update api-ref and release notes for schema validation

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.