From 10f8a9aa127cfaecab368e26c3b896e203e301bc Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Wed, 30 Aug 2017 20:30:19 +0100 Subject: [PATCH] [placement] Require at least one resource class in allocation If an allocation was made with an empty resources object, a 500 response code would result. This change adjusts the schema to use minProperties of 1 to say there must be at least one resource class and value pair in the allocation. If there is not a 400 response is returned. As this is fixing 500 response to a useful error, no microversion is required. A previous gabbi file which demonstrated the problem has been updated to demonstrate that the problem has been fixed. Change-Id: I7d9c64c77586564fb3bdbe92c693bd2a1bc06f24 Closes-Bug: #1714072 --- nova/api/openstack/placement/handlers/allocation.py | 1 + .../placement/gabbits/allocations-bug-1714072.yaml | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/nova/api/openstack/placement/handlers/allocation.py b/nova/api/openstack/placement/handlers/allocation.py index 2d247f1146a5..40ab62bd525d 100644 --- a/nova/api/openstack/placement/handlers/allocation.py +++ b/nova/api/openstack/placement/handlers/allocation.py @@ -51,6 +51,7 @@ ALLOCATION_SCHEMA = { }, "resources": { "type": "object", + "minProperties": 1, "patternProperties": { "^[0-9A-Z_]+$": { "type": "integer", diff --git a/nova/tests/functional/api/openstack/placement/gabbits/allocations-bug-1714072.yaml b/nova/tests/functional/api/openstack/placement/gabbits/allocations-bug-1714072.yaml index 718bfc364d3b..f182508b6297 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/allocations-bug-1714072.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/allocations-bug-1714072.yaml @@ -1,8 +1,7 @@ # Bug 1714072 describes a situation where a resource provider is present in the # body of an allocation, but the resources object is empty. There should be at # least one resource class and value pair. If there is not a 400 response -# should be returned. This gabbit file demonstrates the problem: a 500 on the final -# test. +# should be returned. fixtures: - APIFixture @@ -59,5 +58,6 @@ tests: resources: {} project_id: 42a32c07-3eeb-4401-9373-68a8cdca6784 user_id: 66cb2f29-c86d-47c3-8af5-69ae7b778c70 - # This should be 400 - status: 500 + status: 400 + response_strings: + - does not have enough properties