Set Default and resource limit as defined schema
Default_limit and Resource_limit should not be set as negative values or out of range. This patch addresses the above issue be checking the limit passed by the user should be minimum and maximum to the values defined in schema. If not, then raising the 400 bad request. Also added the test cases for the same. Change-Id: I089f3c231a38be1a1f769a35b4904f5c078d5d07 Closes-Bug: #1797876
This commit is contained in:
parent
9f2b84608e
commit
230ae86a62
|
@ -26,7 +26,9 @@ _registered_limit_properties = {
|
|||
'maxLength': 255
|
||||
},
|
||||
'default_limit': {
|
||||
'type': 'integer'
|
||||
'type': 'integer',
|
||||
'minimum': -1,
|
||||
'maximum': 0x7FFFFFFF # The maximum value a signed INT may have
|
||||
},
|
||||
'description': validation.nullable(parameter_types.description)
|
||||
}
|
||||
|
@ -61,7 +63,9 @@ _limit_create_properties = {
|
|||
'maxLength': 255
|
||||
},
|
||||
'resource_limit': {
|
||||
'type': 'integer'
|
||||
'type': 'integer',
|
||||
'minimum': -1,
|
||||
'maximum': 0x7FFFFFFF # The maximum value a signed INT may have
|
||||
},
|
||||
'description': validation.nullable(parameter_types.description)
|
||||
}
|
||||
|
@ -81,7 +85,9 @@ limit_create = {
|
|||
|
||||
_limit_update_properties = {
|
||||
'resource_limit': {
|
||||
'type': 'integer'
|
||||
'type': 'integer',
|
||||
'minimum': -1,
|
||||
'maximum': 0x7FFFFFFF # The maximum value a signed INT may have
|
||||
},
|
||||
'description': validation.nullable(parameter_types.description)
|
||||
}
|
||||
|
|
|
@ -2563,6 +2563,8 @@ class LimitValidationTestCase(unit.BaseTestCase):
|
|||
{'resource_name': ''},
|
||||
{'resource_name': 'a' * 256},
|
||||
{'default_limit': 'not_int'},
|
||||
{'default_limit': -10},
|
||||
{'default_limit': 10000000000000000},
|
||||
{'description': 123},
|
||||
{'description': True}]
|
||||
for invalid_desc in _INVALID_FORMATS:
|
||||
|
@ -2584,6 +2586,8 @@ class LimitValidationTestCase(unit.BaseTestCase):
|
|||
{'resource_name': ''},
|
||||
{'resource_name': 'a' * 256},
|
||||
{'default_limit': 'not_int'},
|
||||
{'default_limit': -10},
|
||||
{'default_limit': 10000000000000000},
|
||||
{'description': 123}]
|
||||
for invalid_desc in _INVALID_FORMATS:
|
||||
request_to_validate = {'service_id': uuid.uuid4().hex,
|
||||
|
@ -2667,6 +2671,8 @@ class LimitValidationTestCase(unit.BaseTestCase):
|
|||
{'resource_name': 123},
|
||||
{'resource_name': ''},
|
||||
{'resource_name': 'a' * 256},
|
||||
{'resource_limit': -10},
|
||||
{'resource_limit': 10000000000000000},
|
||||
{'resource_limit': 'not_int'},
|
||||
{'description': 123}]
|
||||
for invalid_desc in _INVALID_FORMATS:
|
||||
|
@ -2683,11 +2689,25 @@ class LimitValidationTestCase(unit.BaseTestCase):
|
|||
request_to_validate)
|
||||
|
||||
def test_validate_limit_update_request_with_invalid_input(self):
|
||||
request_to_validate = {'resource_limit': 'not_int'}
|
||||
_INVALID_FORMATS = [{'resource_name': 123},
|
||||
{'resource_limit': 'not_int'},
|
||||
{'resource_name': ''},
|
||||
{'resource_name': 'a' * 256},
|
||||
{'resource_limit': -10},
|
||||
{'resource_limit': 10000000000000000},
|
||||
{'description': 123}]
|
||||
for invalid_desc in _INVALID_FORMATS:
|
||||
request_to_validate = [{'project_id': uuid.uuid4().hex,
|
||||
'service_id': uuid.uuid4().hex,
|
||||
'region_id': 'RegionOne',
|
||||
'resource_name': 'volume',
|
||||
'resource_limit': 10,
|
||||
'description': 'test description'}]
|
||||
request_to_validate[0].update(invalid_desc)
|
||||
|
||||
self.assertRaises(exception.SchemaValidationError,
|
||||
self.update_limits_validator.validate,
|
||||
request_to_validate)
|
||||
self.assertRaises(exception.SchemaValidationError,
|
||||
self.update_limits_validator.validate,
|
||||
request_to_validate)
|
||||
|
||||
def test_validate_limit_create_request_with_addition_input_fails(self):
|
||||
request_to_validate = [{'service_id': uuid.uuid4().hex,
|
||||
|
|
Loading…
Reference in New Issue