diff options
author | Zuul <zuul@review.openstack.org> | 2018-10-05 12:50:14 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2018-10-05 12:50:14 +0000 |
commit | e1faba1dfff96ca290559910c4eb93a9521fae93 (patch) | |
tree | 88aeeaa45e9f0e2f312a5836dc636eaad2ec0846 | |
parent | 37d6f6e376f8244dc1dc2b6abe6c6e305d59dec4 (diff) | |
parent | 3eb967784bbe1c1668d22fdb8cee65dc2417103c (diff) | |
download | nova-e1faba1dfff96ca290559910c4eb93a9521fae93.tar.gz |
Merge "Add check for invalid inventory amounts" into stable/ocata
-rw-r--r-- | nova/api/openstack/placement/handlers/inventory.py | 19 | ||||
-rw-r--r-- | nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml | 84 |
2 files changed, 94 insertions, 9 deletions
diff --git a/nova/api/openstack/placement/handlers/inventory.py b/nova/api/openstack/placement/handlers/inventory.py index cf1fa1b7c2..0995f29f35 100644 --- a/nova/api/openstack/placement/handlers/inventory.py +++ b/nova/api/openstack/placement/handlers/inventory.py @@ -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 } diff --git a/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml b/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml index f7ecbe8be3..0bcb225727 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml @@ -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 |