From 4ad8a86b3019be75a3b5e8ac72e95ff312c8d3cb Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Tue, 19 Apr 2016 12:44:54 -0700 Subject: [PATCH] Fix the schema of assisted_volume_snapshots The position of both 'required' and 'additionalProperties' was wrong and the additionalProperties validation didn't work at all. This patch fixes it by changing the position. Closes-Bug: #1572303 Change-Id: I8eaf7f7c3340321893edcb651983e9133a33e5a1 --- .../schemas/assisted_volume_snapshots.py | 6 ++--- .../api/openstack/compute/test_volumes.py | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/nova/api/openstack/compute/schemas/assisted_volume_snapshots.py b/nova/api/openstack/compute/schemas/assisted_volume_snapshots.py index 4cb2b71bd66e..0b7f3ba2522e 100644 --- a/nova/api/openstack/compute/schemas/assisted_volume_snapshots.py +++ b/nova/api/openstack/compute/schemas/assisted_volume_snapshots.py @@ -43,8 +43,8 @@ snapshots_create = { }, 'required': ['volume_id', 'create_info'], 'additionalProperties': False, - }, - 'required': ['snapshot'], - 'additionalProperties': False, + } }, + 'required': ['snapshot'], + 'additionalProperties': False, } diff --git a/nova/tests/unit/api/openstack/compute/test_volumes.py b/nova/tests/unit/api/openstack/compute/test_volumes.py index 635798cf6e2f..e237f4158c9e 100644 --- a/nova/tests/unit/api/openstack/compute/test_volumes.py +++ b/nova/tests/unit/api/openstack/compute/test_volumes.py @@ -884,11 +884,33 @@ class AssistedSnapshotCreateTestCaseV21(test.NoDBTestCase): self.assertRaises(self.bad_request, self.controller.create, req, body=body) + def test_assisted_create_with_unexpected_attr(self): + req = fakes.HTTPRequest.blank('/v2/fake/os-assisted-volume-snapshots') + body = { + 'snapshot': { + 'volume_id': '1', + 'create_info': { + 'type': 'qcow2', + 'new_file': 'new_file', + 'snapshot_id': 'snapshot_id' + } + }, + 'unexpected': 0, + } + req.method = 'POST' + self.assertRaises(self.bad_request, self.controller.create, + req, body=body) + class AssistedSnapshotCreateTestCaseV2(AssistedSnapshotCreateTestCaseV21): assisted_snaps = assisted_snaps_v2 bad_request = webob.exc.HTTPBadRequest + def test_assisted_create_with_unexpected_attr(self): + # NOTE: legacy v2.0 API cannot handle this kind of invalid requests. + # So we need to skip the test on legacy v2.0 API. + pass + class AssistedSnapshotDeleteTestCaseV21(test.NoDBTestCase): assisted_snaps = assisted_snaps_v21