bgpvpn_routes_control: API definition fixes
* remove spurious comma in range definition for 'local_pref' * add validator to allow a field to be an integer in a range or none and use it for the local_pref parameter * the port association 'routes' attribute can be updated Needed-By: I263e1ee6cf4e1a91be91a4a78f4a160f64d33cc6 Change-Id: I7995209459d5efa020a5e6c6335f4116df7f9f3f
This commit is contained in:
parent
88ad67a60b
commit
0f4733db19
|
@ -705,7 +705,7 @@ bgpvpn-local_pref:
|
|||
bgpvpn-local_pref-request:
|
||||
description: |
|
||||
The default BGP LOCAL_PREF of routes that will be advertised to the
|
||||
BGPVPN (unless overriden per-route).
|
||||
BGPVPN (unless overriden per-route). Defaults to ``null``.
|
||||
in: body
|
||||
required: false
|
||||
type: integer
|
||||
|
|
|
@ -57,7 +57,7 @@ RESOURCE_NAME = bgpvpn.RESOURCE_NAME
|
|||
COLLECTION_NAME = bgpvpn.COLLECTION_NAME
|
||||
|
||||
LOCAL_PREF_KEY = 'local_pref'
|
||||
LOCAL_PREF_RANGE = [0, 2**32-1], # RFC 4271, section 4.3 (p.18)
|
||||
LOCAL_PREF_RANGE = [0, 2**32-1] # RFC 4271, section 4.3 (p.18)
|
||||
|
||||
RESOURCE_ATTRIBUTE_MAP = {
|
||||
COLLECTION_NAME: {
|
||||
|
@ -68,7 +68,7 @@ RESOURCE_ATTRIBUTE_MAP = {
|
|||
'allow_post': True, 'allow_put': True,
|
||||
'is_visible': True,
|
||||
'default': None,
|
||||
'validate': {'type:range': LOCAL_PREF_RANGE},
|
||||
'validate': {'type:range_or_none': LOCAL_PREF_RANGE},
|
||||
'enforce_policy': True}
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ SUB_RESOURCE_ATTRIBUTE_MAP = {
|
|||
'validate': {'type:uuid': None},
|
||||
'is_visible': True,
|
||||
'enforce_policy': True},
|
||||
ROUTES: {'allow_post': True, 'allow_put': False,
|
||||
ROUTES: {'allow_post': True, 'allow_put': True,
|
||||
'default': [],
|
||||
'convert_list_to': converters.convert_kvp_list_to_dict,
|
||||
'validate': {
|
||||
|
|
|
@ -325,6 +325,13 @@ def validate_range(data, valid_values=None):
|
|||
return msg
|
||||
|
||||
|
||||
def validate_range_or_none(data, valid_values=None):
|
||||
"""Check that the provided value is none or a ranged integer"""
|
||||
|
||||
if data is not None:
|
||||
return validate_range(data, valid_values)
|
||||
|
||||
|
||||
def validate_no_whitespace(data):
|
||||
"""Validates that input has no whitespace.
|
||||
|
||||
|
@ -1025,6 +1032,7 @@ validators = {'type:dict': validate_dict,
|
|||
'type:non_negative': validate_non_negative,
|
||||
'type:port_range': validate_port_range_or_none,
|
||||
'type:range': validate_range,
|
||||
'type:range_or_none': validate_range_or_none,
|
||||
'type:regex': validate_regex,
|
||||
'type:regex_or_none': validate_regex_or_none,
|
||||
'type:string': validate_string,
|
||||
|
|
|
@ -319,6 +319,15 @@ class TestAttributeValidation(base.BaseTestCase):
|
|||
msg = validators.validate_range(10, (validators.UNLIMITED, 9))
|
||||
self.assertEqual("'10' is too large - must be no larger than '9'", msg)
|
||||
|
||||
@mock.patch("neutron_lib.api.validators.validate_range")
|
||||
def test_validate_range_or_none(self, mock_validate_range):
|
||||
msg = validators.validate_range_or_none(None, [1, 9])
|
||||
self.assertFalse(mock_validate_range.called)
|
||||
self.assertIsNone(msg)
|
||||
|
||||
validators.validate_range_or_none(1, [1, 9])
|
||||
mock_validate_range.assert_called_once_with(1, [1, 9])
|
||||
|
||||
def _test_validate_mac_address(self, validator, allow_none=False):
|
||||
mac_addr = "ff:16:3e:4f:00:00"
|
||||
msg = validator(mac_addr)
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
features:
|
||||
- Added validator ``range_or_none``.
|
Loading…
Reference in New Issue