From e75e3cb1a14fa2c0b48b8547d7ebc1d55cc23b9b Mon Sep 17 00:00:00 2001 From: zhufl Date: Thu, 27 Sep 2018 14:51:32 +0800 Subject: [PATCH] Add response schema validation for volume quota classes This is to add response schema validation for volume quota classes, also to remove the fields check in testcases. Change-Id: I091e648620d2986d57a8bb2b50399cd1f22fa36f partially-implements: blueprint volume-response-schema-validation --- .../volume/admin/test_volume_quota_classes.py | 4 +- .../response/volume/quota_classes.py | 68 +++++++++++++++++++ .../volume/v3/quota_classes_client.py | 5 +- 3 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 tempest/lib/api_schema/response/volume/quota_classes.py diff --git a/tempest/api/volume/admin/test_volume_quota_classes.py b/tempest/api/volume/admin/test_volume_quota_classes.py index 75dca41e8a..ee52354058 100644 --- a/tempest/api/volume/admin/test_volume_quota_classes.py +++ b/tempest/api/volume/admin/test_volume_quota_classes.py @@ -44,12 +44,10 @@ class VolumeQuotaClassesTest(base.BaseVolumeAdminTest): @decorators.idempotent_id('abb9198e-67d0-4b09-859f-4f4a1418f176') def test_show_default_quota(self): + # response body is validated by schema default_quotas = self.admin_quota_classes_client.show_quota_class_set( 'default')['quota_class_set'] - self.assertIn('id', default_quotas) self.assertEqual('default', default_quotas.pop('id')) - for key in QUOTA_KEYS: - self.assertIn(key, default_quotas) @decorators.idempotent_id('a7644c63-2669-467a-b00e-452dd5c5397b') def test_update_default_quota(self): diff --git a/tempest/lib/api_schema/response/volume/quota_classes.py b/tempest/lib/api_schema/response/volume/quota_classes.py new file mode 100644 index 0000000000..1a575d2c0b --- /dev/null +++ b/tempest/lib/api_schema/response/volume/quota_classes.py @@ -0,0 +1,68 @@ +# Copyright 2018 ZTE Corporation. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +show_quota_classes = { + 'status_code': [200], + 'response_body': { + 'type': 'object', + 'properties': { + 'quota_class_set': { + 'type': 'object', + 'properties': { + 'id': {'type': 'string', 'format': 'uuid'}, + 'volumes': {'type': 'integer'}, + 'snapshots': {'type': 'integer'}, + 'backups': {'type': 'integer'}, + 'groups': {'type': 'integer'}, + 'per_volume_gigabytes': {'type': 'integer'}, + 'gigabytes': {'type': 'integer'}, + 'backup_gigabytes': {'type': 'integer'}, + }, + # for volumes_{volume_type}, etc + "additionalProperties": {'type': 'integer'}, + 'required': ['id', 'volumes', 'snapshots', 'backups', + 'per_volume_gigabytes', 'gigabytes', + 'backup_gigabytes'], + } + }, + 'required': ['quota_class_set'] + } +} + +update_quota_classes = { + 'status_code': [200], + 'response_body': { + 'type': 'object', + 'properties': { + 'quota_class_set': { + 'type': 'object', + 'properties': { + 'volumes': {'type': 'integer'}, + 'snapshots': {'type': 'integer'}, + 'backups': {'type': 'integer'}, + 'groups': {'type': 'integer'}, + 'per_volume_gigabytes': {'type': 'integer'}, + 'gigabytes': {'type': 'integer'}, + 'backup_gigabytes': {'type': 'integer'}, + }, + # for volumes_{volume_type}, etc + "additionalProperties": {'type': 'integer'}, + 'required': ['volumes', 'snapshots', 'backups', + 'per_volume_gigabytes', 'gigabytes', + 'backup_gigabytes'], + } + }, + 'required': ['quota_class_set'] + } +} diff --git a/tempest/lib/services/volume/v3/quota_classes_client.py b/tempest/lib/services/volume/v3/quota_classes_client.py index a8eb53615d..2ed055bdd1 100644 --- a/tempest/lib/services/volume/v3/quota_classes_client.py +++ b/tempest/lib/services/volume/v3/quota_classes_client.py @@ -15,6 +15,7 @@ from oslo_serialization import jsonutils as json +from tempest.lib.api_schema.response.volume import quota_classes as schema from tempest.lib.common import rest_client @@ -30,8 +31,8 @@ class QuotaClassesClient(rest_client.RestClient): """ url = 'os-quota-class-sets/%s' % quota_class_id resp, body = self.get(url) - self.expected_success(200, resp.status) body = json.loads(body) + self.validate_response(schema.show_quota_classes, resp, body) return rest_client.ResponseBody(resp, body) def update_quota_class_set(self, quota_class_id, **kwargs): @@ -44,6 +45,6 @@ class QuotaClassesClient(rest_client.RestClient): url = 'os-quota-class-sets/%s' % quota_class_id put_body = json.dumps({'quota_class_set': kwargs}) resp, body = self.put(url, put_body) - self.expected_success(200, resp.status) body = json.loads(body) + self.validate_response(schema.update_quota_classes, resp, body) return rest_client.ResponseBody(resp, body)