Add check for invalid inventory amounts
This patch adds sane minimum and maximums to the fields for an inventory posting, which will quickly return a 400 error if invalid values are passed instead of proceeding, only to fail at the DB layer. Partial-Bug: #1673227 Change-Id: I6296cee6b8a4be1dd53c52f6290ebda926cf6465
This commit is contained in:
parent
6a6d021f81
commit
0b2d7c4d02
|
@ -35,23 +35,28 @@ BASE_INVENTORY_SCHEMA = {
|
|||
},
|
||||
"total": {
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT
|
||||
"maximum": db.MAX_INT,
|
||||
"minimum": 1,
|
||||
},
|
||||
"reserved": {
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT
|
||||
"maximum": db.MAX_INT,
|
||||
"minimum": 0,
|
||||
},
|
||||
"min_unit": {
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT
|
||||
"maximum": db.MAX_INT,
|
||||
"minimum": 1
|
||||
},
|
||||
"max_unit": {
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT
|
||||
"maximum": db.MAX_INT,
|
||||
"minimum": 1
|
||||
},
|
||||
"step_size": {
|
||||
"type": "integer",
|
||||
"maximum": db.MAX_INT
|
||||
"maximum": db.MAX_INT,
|
||||
"minimum": 1
|
||||
},
|
||||
"allocation_ratio": {
|
||||
"type": "number",
|
||||
|
@ -106,8 +111,8 @@ OUTPUT_INVENTORY_FIELDS = [
|
|||
]
|
||||
INVENTORY_DEFAULTS = {
|
||||
'reserved': 0,
|
||||
'min_unit': 0,
|
||||
'max_unit': 0,
|
||||
'min_unit': 1,
|
||||
'max_unit': db.MAX_INT,
|
||||
'step_size': 1,
|
||||
'allocation_ratio': 1.0
|
||||
}
|
||||
|
|
|
@ -52,7 +52,18 @@ tests:
|
|||
response_json_paths:
|
||||
$.errors[0].title: Bad Request
|
||||
|
||||
- name: post an invalid inventory
|
||||
- name: post an inventory with no total specified
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_class: DISK_GB
|
||||
status: 400
|
||||
response_strings:
|
||||
- JSON does not validate
|
||||
- "'total' is a required property"
|
||||
|
||||
- name: post a negative inventory
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
|
@ -61,9 +72,76 @@ tests:
|
|||
total: -1
|
||||
status: 400
|
||||
response_strings:
|
||||
- Bad inventory DISK_GB for resource provider $ENVIRON['RP_UUID']
|
||||
response_json_paths:
|
||||
$.errors[0].title: Bad Request
|
||||
- JSON does not validate
|
||||
- -1 is less than the minimum of 1
|
||||
|
||||
- name: post an inventory with invalid total
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_class: DISK_GB
|
||||
total: 0
|
||||
reserved: 512
|
||||
min_unit: 1
|
||||
max_unit: 1024
|
||||
step_size: 10
|
||||
allocation_ratio: 1.0
|
||||
status: 400
|
||||
response_strings:
|
||||
- "JSON does not validate: 0 is less than the minimum of 1"
|
||||
- "Failed validating 'minimum' in schema['properties']['total']"
|
||||
|
||||
- name: post an inventory invalid min_unit
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_class: DISK_GB
|
||||
total: 2048
|
||||
reserved: 512
|
||||
min_unit: 0
|
||||
max_unit: 1024
|
||||
step_size: 10
|
||||
allocation_ratio: 1.0
|
||||
status: 400
|
||||
response_strings:
|
||||
- "JSON does not validate: 0 is less than the minimum of 1"
|
||||
- "Failed validating 'minimum' in schema['properties']['min_unit']"
|
||||
|
||||
- name: post an inventory invalid max_unit
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_class: DISK_GB
|
||||
total: 2048
|
||||
reserved: 512
|
||||
min_unit: 10
|
||||
max_unit: 0
|
||||
step_size: 10
|
||||
allocation_ratio: 1.0
|
||||
status: 400
|
||||
response_strings:
|
||||
- "JSON does not validate: 0 is less than the minimum of 1"
|
||||
- "Failed validating 'minimum' in schema['properties']['max_unit']"
|
||||
|
||||
- name: post an inventory invalid step_size
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
request_headers:
|
||||
content-type: application/json
|
||||
data:
|
||||
resource_class: DISK_GB
|
||||
total: 2048
|
||||
reserved: 512
|
||||
min_unit: 10
|
||||
max_unit: 1024
|
||||
step_size: 0
|
||||
allocation_ratio: 1.0
|
||||
status: 400
|
||||
response_strings:
|
||||
- "JSON does not validate: 0 is less than the minimum of 1"
|
||||
- "Failed validating 'minimum' in schema['properties']['step_size']"
|
||||
|
||||
- name: post an inventory
|
||||
POST: /resource_providers/$ENVIRON['RP_UUID']/inventories
|
||||
|
|
Loading…
Reference in New Issue