From 43ae6df96b85c0e008f575193511ebf28b195edd Mon Sep 17 00:00:00 2001 From: EdLeafe Date: Wed, 4 Jan 2017 22:09:15 +0000 Subject: [PATCH] Add check for invalid allocation amounts This patch adds a check for the amounts in allocations passed to the placement API, and returns an error if any amount is not greater than zero. Partial-Bug: #1673227 Change-Id: I2a8dc038d6489e82ad51fdc27d22cf0ab2d66322 (cherry picked from commit 6a6d021f818d6145bd2cdc6431f95f40d8372d59) --- .../placement/handlers/allocation.py | 3 +- .../placement/gabbits/allocations.yaml | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/nova/api/openstack/placement/handlers/allocation.py b/nova/api/openstack/placement/handlers/allocation.py index 2105ef28c8ea..57779613d515 100644 --- a/nova/api/openstack/placement/handlers/allocation.py +++ b/nova/api/openstack/placement/handlers/allocation.py @@ -51,7 +51,8 @@ ALLOCATION_SCHEMA = { "type": "object", "patternProperties": { "^[0-9A-Z_]+$": { - "type": "integer" + "type": "integer", + "minimum": 1, } }, "additionalProperties": False diff --git a/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml b/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml index e91ebb80b059..73d16c7aafd3 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml @@ -93,6 +93,34 @@ tests: max_unit: 1024 status: 201 +- name: put an allocation with zero usage + PUT: /allocations/599ffd2d-526a-4b2e-8683-f13ad25f9958 + request_headers: + content-type: application/json + data: + allocations: + - resource_provider: + uuid: $ENVIRON['RP_UUID'] + resources: + DISK_GB: 0 + status: 400 + response_strings: + - "JSON does not validate: 0 is less than the minimum of 1" + - Failed validating 'minimum' in schema + +- name: put an allocation with omitted usage + PUT: /allocations/599ffd2d-526a-4b2e-8683-f13ad25f9958 + request_headers: + content-type: application/json + data: + allocations: + - resource_provider: + uuid: $ENVIRON['RP_UUID'] + status: 400 + response_strings: + - Failed validating 'required' in schema + + - name: put an allocation PUT: /allocations/599ffd2d-526a-4b2e-8683-f13ad25f9958 request_headers: