Commit Graph

12 Commits

Author SHA1 Message Date
Ghanshyam Mann b26bc7fd7a Multiple API cleanup changes
This microversion implements below API cleanups:

1. 400 for unknown param for query param and for request body.

2. Making server representation always consistent among all APIs
   returning the complete server representation.

3. Change the default return value of ``swap`` field from the empty string
   to 0 (integer) in flavor APIs.

4. Return ``servers`` field always in the response of GET
   hypervisors API even there are no servers on hypervisor

Details: https://specs.openstack.org/openstack/nova-specs/specs/train/approved/api-consistency-cleanup.html

Partial-Implements: blueprint api-consistency-cleanup

Change-Id: I9d257a003d315b84b937dcef91f3cb41f3e24b53
2019-08-12 08:52:38 -05:00
Kevin_Zheng 6029ccd44e Invalid query parameter could lead to HTTP 500
Invalid query parameter could lead to HTTP 500, although
Nova used JSON Schema verification to check input query
params, but query like: GET /servers?limit=%88 will still
lead to HTTP 500, as it failed to parse at webob which is
pre JSON Schema check.

Partial-Bug: #1746202

Change-Id: I11b94a1aaeb67dc1a5abdcf0af5961ee8942a50a
2018-01-31 16:03:43 +08:00
He Jie Xu 134c19faeb Add query parameters white list for server list/detail
This patch enables a white list for query parameter.
The parameters, which are out of white list, will be ignored.

The sort_key still accepts open value. The later patch will add white
list to it.

Co-Authored-By: Zhenyu Zheng <zhengzhenyu@huawei.com>

partial implement of bp add-whitelist-for-server-list-filter-sort-parameters

Change-Id: I7141eef6a1c85ec6d6e8ee170911572535652978
2017-01-17 15:54:15 +00:00
Matt Riedemann 2c6fb02360 Update docstring of _schema_validation_helper
During review of this new helper method there were some comments
about clarifying the docstring for usage. This patch adds the
clarification.

Change-Id: I15177a55768423ae57dce244070de026c34c9418
2017-01-05 12:40:52 -05:00
He Jie Xu 77ad8b89ba Adds support for versioned schema validation for query parameters
The new decorator 'query_schemas' supports the validation of
query parameters. It also supports specifying the minimum and maximum
API microversion of the schema used for validation.

The query parameters will be converted to a dict of lists. For single
value or multiple values parameter, its value will always be a list.
For example, the 'name' parameter is single value parameter and the
'sort_key' is multiple values parameter. They will be converted to the
dict as:

{'name': ['VM1'], 'sort_key': ['display_name', 'updated_at']}

Their JSON-Schema are as below:

name = {'type': 'array', 'items': {'type': 'string'}, 'maxItems': 1}
sort_key = {'type': 'array', 'items': {'type': 'string'}}

To get rid of the duplicated part of JSON-Schema, the macro function
'single_param' and 'multi_params' are added. Their schema can be just
as below:

name = single_param({'type': 'string'})
sort_key = multi_param({'type': 'string'})

Partial of implementation blueprint consistent-query-parameters-validation

Change-Id: I7d5c353680cafbd59692bd462e9d3f8766021310
2017-01-04 17:04:50 +08:00
He Jie Xu a0d47fdefc Refactor the code to add generic schema validation helper
For query parameter validation code to share the code with body schema
validation, this patch move the generic schema validation code out to
a helper method.

Partial of implementation blueprint consistent-query-parameters-validation

Change-Id: I7efde2c3f5c537857c87dacd65f3440e559b6cb6
2016-12-19 22:45:04 +08:00
Ken'ichi Ohmichi 6ae6845c63 Separate API schemas for v2.0 compatible API
We are facing v2 compatibility problems for v2.0 compatible API which
became the default API on /v2 endpoint in Liberty. For fixing these
problems, we need to change some API schemas but we cannot change them
directly because these schemas are used for v2.1 API also and we need
to bump a new microversion for changing them as microversions contract.

To fix these problem without v2.1 API schema changes, this patch
separates the API schemas of v2.0 compatible API from v2.1 API ones.

If we need to separate v2.0 schemas from v2.1, we can specify the
separated schema with '2.0' to the decorator @validation.schema like:

    @validation.schema(schema_v20, '2.0', '2.0')
    @validation.schema(schema, '2.1')
    def update(self, req, id, body):
        ...

Change-Id: If35306b6a9dfc0da355b9edbf4451bf72516da24
2015-09-09 13:37:56 +08:00
He Jie Xu 833940af8d Skip additionalProperties checks when LegacyV2CompatibleWrapper enabled
LegacyV2CompatibleWrapper adds environ variable 'openstack.legacy_v2'
to indicate request coming from v2 request.

Based on 'openstack.legacy_v2' will skip additionalProperties checks
in JSON-Schema validation.

Partial implements blueprint api-relax-validation

Change-Id: Ic95dd0d1b77994ce6e47498c8ae0d7ae079706be
2015-08-06 14:38:45 +08:00
Chris Yeoh 1c7e985000 Adds support for versioned schema validation for microversions api
Adds the ability to specify minimum and maximum API microversion
versions on jsonschema validation decorators. Validation will
only occur through the decorator if the incoming request version
matches the version range specified. If no range is specified then
validation will always occur.

Partially implements blueprint api-microversions

Change-Id: Ia71963161966af3ca0e6e30e2245f12120f8f8d1
2014-12-17 10:05:42 +08:00
Alexander Bochkarev dd4032e9fb Enable flake8 H404 checking
This check indicates on comments in which multi line docstring should
start without a leading new line. This change fixed all violators of
said check.

Change-Id: Ic7357b8c7420767dba611f6fcee07b7700f3aea8
2014-02-27 11:15:55 +04:00
liu-sheng 74f953a1d7 Remove vi modelines
We don't need to have the vi modelines in each source file,
it can be set in a user's vimrc if required.

Also a check is added to hacking to detect if they are re-added.

Change-Id: I347307a5145b2760c69085b6ca850d6a9137ffc6
Closes-Bug: #1229324
2014-02-03 14:19:44 +00:00
Ken'ichi Ohmichi 909e7bf89d Add API input validation framework
This patch adds a core part of API validation framework.
Other patches of each API schema are necessary.

The validation method is implemented with jsonschema library,
and some features are added:
 * validate minimum/maximum value of string number(ex. "10")
 * validate uuid string format

This framework can validate requests of both JSON and XML,
because of validating data after JSON/XML deserialization.

The API schema files for Nova v3 API will be created under
nova/api/openstack/compute/schemas/v3. For preparing these
files, this patch adds some __init__.py files.

blueprint nova-api-validation-fw

Change-Id: Ieba96718264ad2ddfba63b65425f7e5bbb8606a9
2013-11-27 05:45:37 +09:00