Merge "Add response schema validation for volume quota classes"

This commit is contained in:
Zuul
2020-03-16 02:21:32 +00:00
committed by Gerrit Code Review
3 changed files with 72 additions and 5 deletions

View File

@@ -44,12 +44,10 @@ class VolumeQuotaClassesTest(base.BaseVolumeAdminTest):
@decorators.idempotent_id('abb9198e-67d0-4b09-859f-4f4a1418f176') @decorators.idempotent_id('abb9198e-67d0-4b09-859f-4f4a1418f176')
def test_show_default_quota(self): def test_show_default_quota(self):
# response body is validated by schema
default_quotas = self.admin_quota_classes_client.show_quota_class_set( default_quotas = self.admin_quota_classes_client.show_quota_class_set(
'default')['quota_class_set'] 'default')['quota_class_set']
self.assertIn('id', default_quotas)
self.assertEqual('default', default_quotas.pop('id')) 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') @decorators.idempotent_id('a7644c63-2669-467a-b00e-452dd5c5397b')
def test_update_default_quota(self): def test_update_default_quota(self):

View File

@@ -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']
}
}

View File

@@ -15,6 +15,7 @@
from oslo_serialization import jsonutils as json 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 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 url = 'os-quota-class-sets/%s' % quota_class_id
resp, body = self.get(url) resp, body = self.get(url)
self.expected_success(200, resp.status)
body = json.loads(body) body = json.loads(body)
self.validate_response(schema.show_quota_classes, resp, body)
return rest_client.ResponseBody(resp, body) return rest_client.ResponseBody(resp, body)
def update_quota_class_set(self, quota_class_id, **kwargs): 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 url = 'os-quota-class-sets/%s' % quota_class_id
put_body = json.dumps({'quota_class_set': kwargs}) put_body = json.dumps({'quota_class_set': kwargs})
resp, body = self.put(url, put_body) resp, body = self.put(url, put_body)
self.expected_success(200, resp.status)
body = json.loads(body) body = json.loads(body)
self.validate_response(schema.update_quota_classes, resp, body)
return rest_client.ResponseBody(resp, body) return rest_client.ResponseBody(resp, body)