[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
This commit is contained in:
Chris Dent 2017-08-30 20:30:19 +01:00 committed by Matt Riedemann
parent ad2d3fc0f8
commit 10f8a9aa12
2 changed files with 5 additions and 4 deletions

View File

@ -51,6 +51,7 @@ ALLOCATION_SCHEMA = {
},
"resources": {
"type": "object",
"minProperties": 1,
"patternProperties": {
"^[0-9A-Z_]+$": {
"type": "integer",

View File

@ -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