From 128997dd119f4d8e5e44046e165b0240e0769370 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Thu, 19 Jul 2018 10:40:58 +0100 Subject: [PATCH] [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 --- .../api/openstack/placement/schemas/allocation.py | 1 + .../placement/gabbits/allocations-1-12.yaml | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/nova/api/openstack/placement/schemas/allocation.py b/nova/api/openstack/placement/schemas/allocation.py index e149ae3be..7c0313b7f 100644 --- a/nova/api/openstack/placement/schemas/allocation.py +++ b/nova/api/openstack/placement/schemas/allocation.py @@ -115,6 +115,7 @@ ALLOCATION_SCHEMA_V1_12 = { "maxLength": 255 } }, + "additionalProperties": False, "required": [ "allocations", "project_id", diff --git a/nova/tests/functional/api/openstack/placement/gabbits/allocations-1-12.yaml b/nova/tests/functional/api/openstack/placement/gabbits/allocations-1-12.yaml index 13fafda3f..0b951347a 100644 --- a/nova/tests/functional/api/openstack/placement/gabbits/allocations-1-12.yaml +++ b/nova/tests/functional/api/openstack/placement/gabbits/allocations-1-12.yaml @@ -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: