[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
This commit is contained in:
Chris Dent 2017-08-02 21:21:12 +01:00
parent 2decfc77d8
commit 9155da345e
2 changed files with 11 additions and 0 deletions

View File

@ -34,6 +34,7 @@ ALLOCATION_SCHEMA = {
"properties": {
"allocations": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"properties": {

View File

@ -54,6 +54,16 @@ tests:
response_json_paths:
$.errors[0].title: Bad Request
- 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: