Fix resource schemas and releated `get_sorts` test cases

When I'm trying to introduce a central sort-keys validation within
patch [1] to `get_sorts` method in `neutron.api.api_common` module,
I get blocked by some resource schemas and test cases. After reading
neutron API docs and some inspection, I believe there exists uses of
improper sort keys in test cases and some resource schemes need to
keep aligned with offical documents.

* Schemas of resource SecurityGroups/SG Rules/Segments don't provide
`is_sort_key` flag for their sort key properties claimed in offical
docs as neutron-lib does. See [2] for more details.

* Test cases of resource NetworkSegmentRange use unsupported sort keys,
e.g: physical_network. Replace it with `name` property. See [2] for more
details.

[1] https://review.opendev.org/#/c/653903/
[2] https://developer.openstack.org/api-ref/network/v2/index.html

Conflicts:
    neutron/tests/unit/extensions/test_network_segment_range.py

Change-Id: I45a51736e4075e3dbc16827486869d70b659622d
(cherry picked from commit ed3f1087fa)
(cherry picked from commit 874ffe0d6b)
This commit is contained in:
pandatt 2019-05-20 17:55:09 +08:00 committed by Slawek Kaplonski
parent f38aee9555
commit 11b5ba0660
2 changed files with 20 additions and 7 deletions

View File

@ -223,13 +223,16 @@ RESOURCE_ATTRIBUTE_MAP = {
'validate': {'type:uuid': None}, 'validate': {'type:uuid': None},
'is_visible': True, 'is_visible': True,
'is_filter': True, 'is_filter': True,
'is_sort_key': True,
'primary_key': True}, 'primary_key': True},
'name': {'allow_post': True, 'allow_put': True, 'name': {'allow_post': True, 'allow_put': True,
'is_visible': True, 'default': '', 'is_filter': True, 'is_visible': True, 'default': '', 'is_filter': True,
'is_sort_key': True,
'validate': { 'validate': {
'type:name_not_default': db_const.NAME_FIELD_SIZE}}, 'type:name_not_default': db_const.NAME_FIELD_SIZE}},
'tenant_id': {'allow_post': True, 'allow_put': False, 'tenant_id': {'allow_post': True, 'allow_put': False,
'required_by_policy': True, 'required_by_policy': True,
'is_sort_key': True,
'validate': { 'validate': {
'type:string': db_const.PROJECT_ID_FIELD_SIZE}, 'type:string': db_const.PROJECT_ID_FIELD_SIZE},
'is_visible': True, 'is_filter': True}, 'is_visible': True, 'is_filter': True},
@ -241,39 +244,42 @@ RESOURCE_ATTRIBUTE_MAP = {
'validate': {'type:uuid': None}, 'validate': {'type:uuid': None},
'is_visible': True, 'is_visible': True,
'is_filter': True, 'is_filter': True,
'is_sort_key': True,
'primary_key': True}, 'primary_key': True},
'security_group_id': {'allow_post': True, 'allow_put': False, 'security_group_id': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'required_by_policy': True, 'is_visible': True, 'required_by_policy': True,
'is_filter': True}, 'is_sort_key': True, 'is_filter': True},
'remote_group_id': {'allow_post': True, 'allow_put': False, 'remote_group_id': {'allow_post': True, 'allow_put': False,
'default': None, 'is_visible': True, 'default': None, 'is_visible': True,
'is_filter': True}, 'is_sort_key': True, 'is_filter': True},
'direction': {'allow_post': True, 'allow_put': False, 'direction': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'is_filter': True, 'is_visible': True, 'is_filter': True,
'is_sort_key': True,
'validate': {'type:values': ['ingress', 'egress']}}, 'validate': {'type:values': ['ingress', 'egress']}},
'protocol': {'allow_post': True, 'allow_put': False, 'protocol': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': None, 'is_visible': True, 'default': None,
'is_filter': True, 'is_sort_key': True, 'is_filter': True,
'convert_to': convert_protocol}, 'convert_to': convert_protocol},
'port_range_min': {'allow_post': True, 'allow_put': False, 'port_range_min': {'allow_post': True, 'allow_put': False,
'convert_to': convert_validate_port_value, 'convert_to': convert_validate_port_value,
'default': None, 'is_visible': True, 'default': None, 'is_visible': True,
'is_filter': True}, 'is_sort_key': True, 'is_filter': True},
'port_range_max': {'allow_post': True, 'allow_put': False, 'port_range_max': {'allow_post': True, 'allow_put': False,
'convert_to': convert_validate_port_value, 'convert_to': convert_validate_port_value,
'default': None, 'is_visible': True, 'default': None, 'is_visible': True,
'is_filter': True}, 'is_sort_key': True, 'is_filter': True},
'ethertype': {'allow_post': True, 'allow_put': False, 'ethertype': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': 'IPv4', 'is_visible': True, 'default': 'IPv4',
'is_filter': True, 'is_filter': True, 'is_sort_key': True,
'convert_to': convert_ethertype_to_case_insensitive, 'convert_to': convert_ethertype_to_case_insensitive,
'validate': {'type:values': sg_supported_ethertypes}}, 'validate': {'type:values': sg_supported_ethertypes}},
'remote_ip_prefix': {'allow_post': True, 'allow_put': False, 'remote_ip_prefix': {'allow_post': True, 'allow_put': False,
'default': None, 'is_visible': True, 'default': None, 'is_visible': True,
'is_filter': True, 'is_sort_key': True, 'is_filter': True,
'convert_to': convert_ip_prefix_to_cidr}, 'convert_to': convert_ip_prefix_to_cidr},
'tenant_id': {'allow_post': True, 'allow_put': False, 'tenant_id': {'allow_post': True, 'allow_put': False,
'required_by_policy': True, 'required_by_policy': True,
'is_sort_key': True,
'validate': { 'validate': {
'type:string': db_const.PROJECT_ID_FIELD_SIZE}, 'type:string': db_const.PROJECT_ID_FIELD_SIZE},
'is_visible': True, 'is_filter': True}, 'is_visible': True, 'is_filter': True},

View File

@ -45,17 +45,20 @@ RESOURCE_ATTRIBUTE_MAP = {
'allow_put': False, 'allow_put': False,
'validate': {'type:uuid': None}, 'validate': {'type:uuid': None},
'is_filter': True, 'is_filter': True,
'is_sort_key': True,
'is_visible': True, 'is_visible': True,
'primary_key': True}, 'primary_key': True},
'tenant_id': {'allow_post': True, 'tenant_id': {'allow_post': True,
'allow_put': False, 'allow_put': False,
'validate': {'type:string': 'validate': {'type:string':
db_const.PROJECT_ID_FIELD_SIZE}, db_const.PROJECT_ID_FIELD_SIZE},
'is_sort_key': True,
'is_visible': False}, 'is_visible': False},
'network_id': {'allow_post': True, 'network_id': {'allow_post': True,
'allow_put': False, 'allow_put': False,
'validate': {'type:uuid': None}, 'validate': {'type:uuid': None},
'is_filter': True, 'is_filter': True,
'is_sort_key': True,
'is_visible': True}, 'is_visible': True},
PHYSICAL_NETWORK: {'allow_post': True, PHYSICAL_NETWORK: {'allow_post': True,
'allow_put': False, 'allow_put': False,
@ -63,23 +66,27 @@ RESOURCE_ATTRIBUTE_MAP = {
'validate': {'type:string': 'validate': {'type:string':
providernet.PHYSICAL_NETWORK_MAX_LEN}, providernet.PHYSICAL_NETWORK_MAX_LEN},
'is_filter': True, 'is_filter': True,
'is_sort_key': True,
'is_visible': True}, 'is_visible': True},
NETWORK_TYPE: {'allow_post': True, NETWORK_TYPE: {'allow_post': True,
'allow_put': False, 'allow_put': False,
'validate': {'type:string': 'validate': {'type:string':
providernet.NETWORK_TYPE_MAX_LEN}, providernet.NETWORK_TYPE_MAX_LEN},
'is_filter': True, 'is_filter': True,
'is_sort_key': True,
'is_visible': True}, 'is_visible': True},
SEGMENTATION_ID: {'allow_post': True, SEGMENTATION_ID: {'allow_post': True,
'allow_put': False, 'allow_put': False,
'default': constants.ATTR_NOT_SPECIFIED, 'default': constants.ATTR_NOT_SPECIFIED,
'convert_to': converters.convert_to_int, 'convert_to': converters.convert_to_int,
'is_sort_key': True,
'is_visible': True}, 'is_visible': True},
'name': {'allow_post': True, 'name': {'allow_post': True,
'allow_put': True, 'allow_put': True,
'default': constants.ATTR_NOT_SPECIFIED, 'default': constants.ATTR_NOT_SPECIFIED,
'validate': {'type:string_or_none': NAME_LEN}, 'validate': {'type:string_or_none': NAME_LEN},
'is_filter': True, 'is_filter': True,
'is_sort_key': True,
'is_visible': True} 'is_visible': True}
}, },
subnet_def.COLLECTION_NAME: { subnet_def.COLLECTION_NAME: {