Merge "Add response schema validation for volume pools"

This commit is contained in:
Zuul 2020-05-26 15:13:34 +00:00 committed by Gerrit Code Review
commit a9ef5dbc73
3 changed files with 91 additions and 5 deletions

View File

@ -0,0 +1,79 @@
# 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.
from tempest.lib.api_schema.response.compute.v2_1 import parameter_types
get_pools_no_detail = {
'status_code': [200],
'response_body': {
'type': 'object',
'properties': {
'pools': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
},
'additionalProperties': False,
'required': ['name']
}
}
},
'additionalProperties': False,
'required': ['pools'],
}
}
get_pools_with_detail = {
'status_code': [200],
'response_body': {
'type': 'object',
'properties': {
'pools': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'name': {'type': 'string'},
'capabilities': {
'type': ['object', 'null'],
'properties': {
'updated': parameter_types.date_time_or_null,
'QoS_support': {'type': 'boolean'},
'total_capacity_gb': {
'type': ['number', 'string']
},
'volume_backend_name': {'type': 'string'},
'free_capacity_gb': {
'type': ['number', 'string']
},
'driver_version': {'type': 'string'},
'reserved_percentage': {'type': 'integer'},
'storage_protocol': {'type': 'string'},
'vendor_name': {'type': 'string'},
'timestamp': parameter_types.date_time_or_null
},
# Because some legacy volumes or backends may not
# support pools, so no required fields here.
},
},
'additionalProperties': False,
'required': ['name', 'capabilities']
}
}
},
'additionalProperties': False,
'required': ['pools'],
}
}

View File

@ -15,6 +15,7 @@
from oslo_serialization import jsonutils as json
from tempest.lib.api_schema.response.volume import scheduler_stats as schema
from tempest.lib.common import rest_client
@ -28,9 +29,11 @@ class SchedulerStatsClient(rest_client.RestClient):
https://docs.openstack.org/api-ref/block-storage/v3/index.html#list-all-back-end-storage-pools
"""
url = 'scheduler-stats/get_pools'
schema_get_pools = schema.get_pools_no_detail
if detail:
url += '?detail=True'
schema_get_pools = schema.get_pools_with_detail
resp, body = self.get(url)
body = json.loads(body)
self.expected_success(200, resp.status)
self.validate_response(schema_get_pools, resp, body)
return rest_client.ResponseBody(resp, body)

View File

@ -25,12 +25,14 @@ class TestSchedulerStatsClient(base.BaseServiceTest):
"name": "pool1",
"capabilities": {
"updated": "2014-10-28T00:00:00-00:00",
"total_capacity": 1024,
"free_capacity": 100,
"total_capacity_gb": 1024,
"free_capacity_gb": 100,
"volume_backend_name": "pool1",
"reserved_percentage": 0,
"driver_version": "1.0.0",
"timestamp": "2014-10-28T00:00:00-00:00",
"storage_protocol": "iSCSI",
"vendor_name": "vendor",
"QoS_support": False
}
},
@ -38,12 +40,14 @@ class TestSchedulerStatsClient(base.BaseServiceTest):
"name": "pool2",
"capabilities": {
"updated": "2014-10-28T00:00:00-00:00",
"total_capacity": 512,
"free_capacity": 200,
"total_capacity_gb": 512,
"free_capacity_gb": 200,
"volume_backend_name": "pool2",
"reserved_percentage": 0,
"driver_version": "1.0.2",
"timestamp": "2014-10-28T00:00:00-00:00",
"storage_protocol": "iSER",
"vendor_name": "vendor",
"QoS_support": True
}
}