Merge "api: allow any scheduler hints"
This commit is contained in:
commit
40dbe07b14
nova
api
tests/unit/api/openstack
@ -52,7 +52,11 @@ _hints = {
|
||||
'pattern': '^\/[0-9a-f.:]+$'
|
||||
},
|
||||
},
|
||||
'additionalProperties': False
|
||||
# NOTE: As this Mail:
|
||||
# http://lists.openstack.org/pipermail/openstack-dev/2015-June/067996.html
|
||||
# pointed out the limit the scheduler-hints in the API is problematic. So
|
||||
# relax it.
|
||||
'additionalProperties': True
|
||||
}
|
||||
|
||||
|
||||
|
@ -75,13 +75,29 @@ def _validate_uri(instance):
|
||||
require_authority=True)
|
||||
|
||||
|
||||
def _soft_validate_additional_properties(validator, aP, instance, schema):
|
||||
def _soft_validate_additional_properties(validator,
|
||||
additional_properties_value,
|
||||
instance,
|
||||
schema):
|
||||
"""This validator function is used for legacy v2 compatible mode in v2.1.
|
||||
This will skip all the addtional properties checking but keep check the
|
||||
'patternProperties'. 'patternProperties' is used for metadata API.
|
||||
|
||||
If there are not any properties on the instance that are not specified in
|
||||
the schema, this will return without any effect. If there are any such
|
||||
extra properties, they will be handled as follows:
|
||||
|
||||
- if the schema has an additionalProperties value of True, the extra
|
||||
properties on the instance will not be touched.
|
||||
- if the schema has an additionalProperties value of False and there
|
||||
aren't patternProperties specified, the extra properties will be stripped
|
||||
from the instance.
|
||||
- if the schema has an additionalProperties value of False and there
|
||||
are patternProperties specified, the extra properties will not be
|
||||
touched and raise validation error if pattern doesn't match.
|
||||
"""
|
||||
if not validator.is_type(instance, "object"):
|
||||
if (not validator.is_type(instance, "object") or
|
||||
additional_properties_value):
|
||||
return
|
||||
|
||||
properties = schema.get("properties", {})
|
||||
|
@ -121,12 +121,25 @@ class TestSoftAddtionalPropertiesValidation(test.NoDBTestCase):
|
||||
'bar': {'type': 'string'}
|
||||
},
|
||||
'additionalProperties': False}
|
||||
self.schema_allow = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'foo': {'type': 'string'},
|
||||
'bar': {'type': 'string'}
|
||||
},
|
||||
'additionalProperties': True}
|
||||
self.schema_with_pattern = {
|
||||
'type': 'object',
|
||||
'patternProperties': {
|
||||
'^[a-zA-Z0-9-_:. ]{1,255}$': {'type': 'string'}
|
||||
},
|
||||
'additionalProperties': False}
|
||||
self.schema_allow_with_pattern = {
|
||||
'type': 'object',
|
||||
'patternProperties': {
|
||||
'^[a-zA-Z0-9-_:. ]{1,255}$': {'type': 'string'}
|
||||
},
|
||||
'additionalProperties': True}
|
||||
|
||||
def test_strip_extra_properties_out_without_extra_props(self):
|
||||
validator = validators._SchemaValidator(self.schema).validator
|
||||
@ -144,6 +157,23 @@ class TestSoftAddtionalPropertiesValidation(test.NoDBTestCase):
|
||||
self.assertRaises(StopIteration, gen.next)
|
||||
self.assertEqual({'foo': '1'}, instance)
|
||||
|
||||
def test_not_strip_extra_properties_out_with_allow_extra_props(self):
|
||||
validator = validators._SchemaValidator(self.schema_allow).validator
|
||||
instance = {'foo': '1', 'extra_foo': 'extra'}
|
||||
gen = validators._soft_validate_additional_properties(
|
||||
validator, True, instance, self.schema_allow)
|
||||
self.assertRaises(StopIteration, gen.next)
|
||||
self.assertEqual({'foo': '1', 'extra_foo': 'extra'}, instance)
|
||||
|
||||
def test_pattern_properties_with_invalid_property_and_allow_extra_props(
|
||||
self):
|
||||
validator = validators._SchemaValidator(
|
||||
self.schema_with_pattern).validator
|
||||
instance = {'foo': '1', 'b' * 300: 'extra'}
|
||||
gen = validators._soft_validate_additional_properties(
|
||||
validator, True, instance, self.schema_with_pattern)
|
||||
self.assertRaises(StopIteration, gen.next)
|
||||
|
||||
def test_pattern_properties(self):
|
||||
validator = validators._SchemaValidator(
|
||||
self.schema_with_pattern).validator
|
||||
|
Loading…
x
Reference in New Issue
Block a user