Handle maximum limit in schema for int and float type parameters
Create/update inventory APIs returns 500 error if you pass value greater than db.MAX_INT (2147483647) for total, reserved, min_unit, max_unit, step_size int type parameters and db.SQL_SP_FLOAT_MAX (3.40282e+38) for allocation_ratio. Added maximum limit check in schema to ensure value is not greater than maximum limit permitted by db for all mentioned parameters. Closes-Bug: #1642484 Change-Id: I5b8c3c175ca617ae7bb82b81b0fe608ae1755b72
This commit is contained in:
parent
e730b523ed
commit
e79fb5d631
@ -18,6 +18,7 @@ from oslo_serialization import jsonutils
|
||||
import webob
|
||||
|
||||
from nova.api.openstack.placement import util
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.i18n import _
|
||||
from nova import objects
|
||||
@ -30,22 +31,28 @@ BASE_INVENTORY_SCHEMA = {
|
||||
"type": "integer"
|
||||
},
|
||||
"total": {
|
||||
"type": "integer"
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT
|
||||
},
|
||||
"reserved": {
|
||||
"type": "integer"
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT
|
||||
},
|
||||
"min_unit": {
|
||||
"type": "integer"
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT
|
||||
},
|
||||
"max_unit": {
|
||||
"type": "integer"
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT
|
||||
},
|
||||
"step_size": {
|
||||
"type": "integer"
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT
|
||||
},
|
||||
"allocation_ratio": {
|
||||
"type": "number"
|
||||
"type": "number",
|
||||
"maximum": db.SQL_SP_FLOAT_MAX
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
|
@ -345,6 +345,131 @@ tests:
|
||||
response_strings:
|
||||
- Unknown resource class in inventory
|
||||
|
||||
- name: post an inventory with total exceed max limit
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_class: DISK_GB
|
||||
total: 2147483648
|
||||
reserved: 512
|
||||
min_unit: 10
|
||||
max_unit: 1024
|
||||
step_size: 10
|
||||
allocation_ratio: 1.0
|
||||
status: 400
|
||||
response_strings:
|
||||
- "Failed validating 'maximum'"
|
||||
|
||||
- name: post an inventory with reserved exceed max limit
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_class: DISK_GB
|
||||
total: 1024
|
||||
reserved: 2147483648
|
||||
min_unit: 10
|
||||
max_unit: 1024
|
||||
step_size: 10
|
||||
allocation_ratio: 1.0
|
||||
status: 400
|
||||
response_strings:
|
||||
- "Failed validating 'maximum'"
|
||||
|
||||
- name: post an inventory with min_unit exceed max limit
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_class: DISK_GB
|
||||
total: 1024
|
||||
reserved: 512
|
||||
min_unit: 2147483648
|
||||
max_unit: 1024
|
||||
step_size: 10
|
||||
allocation_ratio: 1.0
|
||||
status: 400
|
||||
response_strings:
|
||||
- "Failed validating 'maximum'"
|
||||
|
||||
- name: post an inventory with max_unit exceed max limit
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_class: DISK_GB
|
||||
total: 1024
|
||||
reserved: 512
|
||||
min_unit: 10
|
||||
max_unit: 2147483648
|
||||
step_size: 10
|
||||
allocation_ratio: 1.0
|
||||
status: 400
|
||||
response_strings:
|
||||
- "Failed validating 'maximum'"
|
||||
|
||||
- name: post an inventory with step_size exceed max limit
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_class: DISK_GB
|
||||
total: 1024
|
||||
reserved: 512
|
||||
min_unit: 10
|
||||
max_unit: 1024
|
||||
step_size: 2147483648
|
||||
allocation_ratio: 1.0
|
||||
status: 400
|
||||
response_strings:
|
||||
- "Failed validating 'maximum'"
|
||||
|
||||
- name: post an inventory with allocation_ratio exceed max limit
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_class: DISK_GB
|
||||
total: 1024
|
||||
reserved: 512
|
||||
min_unit: 10
|
||||
max_unit: 1024
|
||||
step_size: 10
|
||||
allocation_ratio: 3.40282e+39
|
||||
status: 400
|
||||
response_strings:
|
||||
- "Failed validating 'maximum'"
|
||||
|
||||
- name: modify the inventory with total exceed max limit
|
||||
PUT: $LAST_URL
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_provider_generation: 1
|
||||
inventories:
|
||||
DISK_GB:
|
||||
total: 2147483648
|
||||
reserved: 512
|
||||
status: 400
|
||||
response_strings:
|
||||
- "Failed validating 'maximum'"
|
||||
|
||||
- name: modify the inventory with allocation_ratio exceed max limit
|
||||
PUT: $LAST_URL
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_provider_generation: 1
|
||||
inventories:
|
||||
DISK_GB:
|
||||
total: 1024
|
||||
reserved: 512
|
||||
allocation_ratio: 3.40282e+39
|
||||
status: 400
|
||||
response_strings:
|
||||
- "Failed validating 'maximum'"
|
||||
|
||||
# NOTE(cdent): The generation is 6 now, based on the activity at
|
||||
# the start of this file.
|
||||
- name: put all inventory bad capacity
|
||||
|
Loading…
x
Reference in New Issue
Block a user