From c95cd011d01f7e5cbd10346223be995f6507f9e7 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Wed, 2 Aug 2017 21:21:12 +0100 Subject: [PATCH] [placement] Require at least one allocation when PUT When doing a PUT to /allocations/{consumer_uuid} if the list of allocations is empty there is a 500 error coming from an uncaught IndexError. Adjust the schema to require at least one allocation. If no allocations are provided in the list, the response will be a 400. This doesn't require a microversion because it is changing a 500 to a useful response. Change-Id: I361fa1e534d7b20c985558e272b672b84c6fe439 Closes-Bug: #1708260 (cherry picked from commit 9155da345e5d6d1aee293bc66f746da52bca4c79) --- nova/api/openstack/placement/handlers/allocation.py | 1 + .../api/openstack/placement/gabbits/allocations.yaml | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/nova/api/openstack/placement/handlers/allocation.py b/nova/api/openstack/placement/handlers/allocation.py index 545957c29e29..2105ef28c8ea 100644 --- a/nova/api/openstack/placement/handlers/allocation.py +++ b/nova/api/openstack/placement/handlers/allocation.py @@ -32,6 +32,7 @@ ALLOCATION_SCHEMA = { "properties": { "allocations": { "type": "array", + "minItems": 1, "items": { "type": "object", "properties": { diff --git a/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml b/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml index 86b6e7072118..e91ebb80b059 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/allocations.yaml @@ -48,6 +48,16 @@ tests: content-type: application/json status: 400 +- name: put an allocation empty list + PUT: /allocations/599ffd2d-526a-4b2e-8683-f13ad25f9958 + request_headers: + content-type: application/json + data: + allocations: [] + status: 400 + response_strings: + - "Failed validating 'minItems'" + - name: put an allocation violate schema PUT: /allocations/599ffd2d-526a-4b2e-8683-f13ad25f9958 request_headers: