Merge "Add check for invalid inventory amounts" into stable/ocata

This commit is contained in:
Zuul 2018-10-05 12:50:14 +00:00 committed by Gerrit Code Review
commit e1faba1dff
2 changed files with 94 additions and 9 deletions

View File

@ -33,23 +33,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",
@ -104,8 +109,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
}

View File

@ -41,7 +41,18 @@ tests:
response_strings:
- Unable to create inventory for resource provider
- 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
@ -50,7 +61,76 @@ tests:
total: -1
status: 400
response_strings:
- Bad inventory DISK_GB for resource provider $ENVIRON['RP_UUID']
- 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