diff --git a/api-ref/source/v2/intro.inc b/api-ref/source/v2/intro.inc index 9c063c7fb..05a0197b4 100644 --- a/api-ref/source/v2/intro.inc +++ b/api-ref/source/v2/intro.inc @@ -156,6 +156,12 @@ that have ``device_id`` attribute with empty value (which are unbound ports). To determine if this feature is supported, a user can check whether the ``empty-string-filtering`` extension API is available. +Starting from Rocky release, the Networking API will perform validation +on filtering attributes if the API extension ``filter-validation`` is +available. If an API request contains an unknown or unsupported +parameter, the server will return a ``400`` response instead of silently +ignoring the invalid input. + Note ---- diff --git a/neutron_lib/api/definitions/__init__.py b/neutron_lib/api/definitions/__init__.py index 4081b04a1..4f0fc4eef 100644 --- a/neutron_lib/api/definitions/__init__.py +++ b/neutron_lib/api/definitions/__init__.py @@ -33,6 +33,7 @@ from neutron_lib.api.definitions import empty_string_filtering from neutron_lib.api.definitions import external_net from neutron_lib.api.definitions import extra_dhcp_opt from neutron_lib.api.definitions import extraroute +from neutron_lib.api.definitions import filter_validation from neutron_lib.api.definitions import fip64 from neutron_lib.api.definitions import fip_port_details from neutron_lib.api.definitions import firewall @@ -118,6 +119,7 @@ _ALL_API_DEFINITIONS = { external_net, extra_dhcp_opt, extraroute, + filter_validation, fip64, firewall, firewall_v2, diff --git a/neutron_lib/api/definitions/base.py b/neutron_lib/api/definitions/base.py index 4490425c3..a2213b4eb 100644 --- a/neutron_lib/api/definitions/base.py +++ b/neutron_lib/api/definitions/base.py @@ -91,6 +91,7 @@ KNOWN_EXTENSIONS = ( 'external-net', 'extra_dhcp_opt', 'extraroute', + 'filter-validation', 'fip-port-details', 'flavors', 'floating-ip-port-forwarding', diff --git a/neutron_lib/api/definitions/filter_validation.py b/neutron_lib/api/definitions/filter_validation.py new file mode 100644 index 000000000..a79ede04b --- /dev/null +++ b/neutron_lib/api/definitions/filter_validation.py @@ -0,0 +1,25 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +ALIAS = 'filter-validation' +IS_SHIM_EXTENSION = True +IS_STANDARD_ATTR_EXTENSION = False +NAME = 'Filter parameters validation' +DESCRIPTION = 'Provides validation on filter parameters.' +UPDATED_TIMESTAMP = '2018-07-04T10:00:00-00:00' +RESOURCE_ATTRIBUTE_MAP = {} +SUB_RESOURCE_ATTRIBUTE_MAP = {} +ACTION_MAP = {} +REQUIRED_EXTENSIONS = [] +OPTIONAL_EXTENSIONS = [] +ACTION_STATUS = {} diff --git a/neutron_lib/tests/unit/api/definitions/test_filter_validation.py b/neutron_lib/tests/unit/api/definitions/test_filter_validation.py new file mode 100644 index 000000000..623b98cf2 --- /dev/null +++ b/neutron_lib/tests/unit/api/definitions/test_filter_validation.py @@ -0,0 +1,18 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from neutron_lib.api.definitions import filter_validation as apidef +from neutron_lib.tests.unit.api.definitions import base + + +class FilterValidationiDefinitionTestCase(base.DefinitionBaseTestCase): + extension_module = apidef diff --git a/releasenotes/notes/add-filter-validation-api-extension-15cc667d5498f163.yaml b/releasenotes/notes/add-filter-validation-api-extension-15cc667d5498f163.yaml new file mode 100644 index 000000000..70f9617fa --- /dev/null +++ b/releasenotes/notes/add-filter-validation-api-extension-15cc667d5498f163.yaml @@ -0,0 +1,12 @@ +--- +features: + - | + Add API extension ``filter-validation``. This extension indicates if the + server supports validation on filter parameters of the list requests. +other: + - | + API extension ``filter-validation`` relies on the ``is_filter`` keyword + in the ``RESOURCE_ATTRIBUTE_MAP`` to judge if an attribute can be used as + filter. Neutron plugins which want to support filter validation + needs to set ``is_filter`` to ``True`` for each attribute in their + resource attribute map.