diff --git a/api-ref/source/v2/intro.inc b/api-ref/source/v2/intro.inc index 9c063c7fb..45de9c1b8 100644 --- a/api-ref/source/v2/intro.inc +++ b/api-ref/source/v2/intro.inc @@ -378,6 +378,12 @@ the background. To determine if sorting is supported, a user can check whether the 'sorting' extension API is available. +Starting from Rocky release, the Networking API performs validation on +sorting attributes if the API extension ``sort-key-validation`` is available. +If an API request contains an unknown or unsupported sort key, +the server will return a ``400`` response instead of silently ignoring +the invalid input. + .. _Extensions: diff --git a/neutron_lib/api/definitions/__init__.py b/neutron_lib/api/definitions/__init__.py index 4081b04a1..a7a3a957d 100644 --- a/neutron_lib/api/definitions/__init__.py +++ b/neutron_lib/api/definitions/__init__.py @@ -79,6 +79,7 @@ from neutron_lib.api.definitions import segment from neutron_lib.api.definitions import segments_peer_subnet_host_routes from neutron_lib.api.definitions import servicetype from neutron_lib.api.definitions import sfc +from neutron_lib.api.definitions import sort_key_validation from neutron_lib.api.definitions import sorting from neutron_lib.api.definitions import standard_attr_segment from neutron_lib.api.definitions import subnet @@ -164,6 +165,7 @@ _ALL_API_DEFINITIONS = { segments_peer_subnet_host_routes, servicetype, sfc, + sort_key_validation, sorting, standard_attr_segment, subnet, diff --git a/neutron_lib/api/definitions/base.py b/neutron_lib/api/definitions/base.py index 4490425c3..d42f5bfeb 100644 --- a/neutron_lib/api/definitions/base.py +++ b/neutron_lib/api/definitions/base.py @@ -116,6 +116,7 @@ KNOWN_EXTENSIONS = ( 'security-group', 'segment', 'service-type', + 'sort-key-validation', 'sorting', 'standard-attr-description', 'standard-attr-revisions', diff --git a/neutron_lib/api/definitions/sort_key_validation.py b/neutron_lib/api/definitions/sort_key_validation.py new file mode 100644 index 000000000..350b0a6c7 --- /dev/null +++ b/neutron_lib/api/definitions/sort_key_validation.py @@ -0,0 +1,27 @@ +# 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 sorting + + +ALIAS = 'sort-key-validation' +IS_SHIM_EXTENSION = True +IS_STANDARD_ATTR_EXTENSION = False +NAME = 'Sort keys validation' +DESCRIPTION = 'Provides validation on sort keys.' +UPDATED_TIMESTAMP = '2018-07-04T10:00:00-00:00' +RESOURCE_ATTRIBUTE_MAP = {} +SUB_RESOURCE_ATTRIBUTE_MAP = {} +ACTION_MAP = {} +REQUIRED_EXTENSIONS = [sorting.ALIAS] +OPTIONAL_EXTENSIONS = [] +ACTION_STATUS = {} diff --git a/neutron_lib/tests/unit/api/definitions/test_sort_key_validation.py b/neutron_lib/tests/unit/api/definitions/test_sort_key_validation.py new file mode 100644 index 000000000..650f63b52 --- /dev/null +++ b/neutron_lib/tests/unit/api/definitions/test_sort_key_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 sort_key_validation as apidef +from neutron_lib.tests.unit.api.definitions import base + + +class SortKeyValidationiDefinitionTestCase(base.DefinitionBaseTestCase): + extension_module = apidef diff --git a/releasenotes/notes/add-api-extension-sort-key-validation-b42f5839671fe5f5.yaml b/releasenotes/notes/add-api-extension-sort-key-validation-b42f5839671fe5f5.yaml new file mode 100644 index 000000000..3af695536 --- /dev/null +++ b/releasenotes/notes/add-api-extension-sort-key-validation-b42f5839671fe5f5.yaml @@ -0,0 +1,12 @@ +--- +features: + - | + Add API extension ``sort-key-validation``. This extension indicates if the + server supports validation on sorting. +other: + - | + API extension ``sort-key-validation`` relies on the ``is_sort_key`` keyword + in the ``RESOURCE_ATTRIBUTE_MAP`` to judge if an attribute can be used as + sort key. Neutron plugins which want to support sort key validation + needs to set ``is_sort_key`` to ``True`` for each attribute in their + resource attribute map.