[placement] disallow additional fields in allocations

Back in microversion 1.12, when the allocations structure was extended
to allow project_id and user_id on PUT /allocations/{uuid},
"additionalProperties" was not set in the JSON schema, so it has been
possible since then to include unused fields in the input. The schema
was then reused in the creation of subsequent schema for new
microversions and for new URIs, such as POST /allocations and the
forthcoming /reshaper.

This change fixes it by fixing the old microversion. This is the "just
fix it" option from the discussion on the associated bug. The other
option is to create a new microversion that corrects the behavior. This
is more complex than it might initially sound because of the way in
which the original schema is used to compose new ones.

Change-Id: Ied464744803864e61a45e03c559760a8a2e2581f
Closes-Bug: #1782340
This commit is contained in:
Chris Dent 2018-07-19 10:40:58 +01:00
parent 50f40854b0
commit 0fc4f95914
2 changed files with 16 additions and 0 deletions

View File

@ -115,6 +115,7 @@ ALLOCATION_SCHEMA_V1_12 = {
"maxLength": 255
}
},
"additionalProperties": False,
"required": [
"allocations",
"project_id",

View File

@ -65,6 +65,21 @@ tests:
- JSON does not validate
- does not have enough properties
- name: put unused field
PUT: /allocations/a0b15655-273a-4b3d-9792-2e579b7d5ad9
data:
allocations:
$ENVIRON['RP_UUID']:
resources:
VCPU: 1
DISK_GB: 20
project_id: 42a32c07-3eeb-4401-9373-68a8cdca6784
user_id: 66cb2f29-c86d-47c3-8af5-69ae7b778c70
bad_field: moo
status: 400
response_strings:
- JSON does not validate
- name: create the resource provider
POST: /resource_providers
request_headers: