From e79fb5d631fa68aefa8c20755fd2b2a9a836cd53 Mon Sep 17 00:00:00 2001 From: bhagyashris Date: Wed, 30 Nov 2016 20:45:54 +0530 Subject: [PATCH] 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 --- .../openstack/placement/handlers/inventory.py | 19 ++- .../placement/gabbits/inventory.yaml | 125 ++++++++++++++++++ 2 files changed, 138 insertions(+), 6 deletions(-) diff --git a/nova/api/openstack/placement/handlers/inventory.py b/nova/api/openstack/placement/handlers/inventory.py index ff4da6cd4..6fd024923 100644 --- a/nova/api/openstack/placement/handlers/inventory.py +++ b/nova/api/openstack/placement/handlers/inventory.py @@ -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": [ diff --git a/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml b/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml index 471fb114d..f7ecbe8be 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/inventory.yaml @@ -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