Browse Source

Merge "Add response schema validation for volume group snapshots"

changes/87/744087/1
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
00041e686f
2 changed files with 114 additions and 5 deletions
  1. +106
    -0
      tempest/lib/api_schema/response/volume/group_snapshots.py
  2. +8
    -5
      tempest/lib/services/volume/v3/group_snapshots_client.py

+ 106
- 0
tempest/lib/api_schema/response/volume/group_snapshots.py View File

@@ -0,0 +1,106 @@
# Copyright 2015 NEC 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

create_group_snapshot = {
'status_code': [202],
'response_body': {
'type': 'object',
'properties': {
'group_snapshot': {
'type': 'object',
'properties': {
'id': {'type': 'string', 'format': 'uuid'},
'name': {'type': 'string'},
'group_type_id': {'type': 'string', 'format': 'uuid'},
},
'additionalProperties': False,
'required': ['id', 'name', 'group_type_id']
}
},
'additionalProperties': False,
'required': ['group_snapshot']
}
}

delete_group_snapshot = {'status_code': [202]}

common_show_group_snapshot = {
'type': 'object',
'properties': {
'created_at': parameter_types.date_time,
'group_id': {'type': 'string', 'format': 'uuid'},
'id': {'type': 'string', 'format': 'uuid'},
'name': {'type': 'string'},
'status': {'type': 'string'},
'description': {'type': ['string', 'null']},
'group_type_id': {'type': 'string', 'format': 'uuid'},
},
'additionalProperties': False,
'required': ['created_at', 'group_id', 'id', 'name',
'status', 'description', 'group_type_id']
}

show_group_snapshot = {
'status_code': [200],
'response_body': {
'type': 'object',
'properties': {
'group_snapshot': common_show_group_snapshot
},
'additionalProperties': False,
'required': ['group_snapshot']
}
}

list_group_snapshots_no_detail = {
'status_code': [200],
'response_body': {
'type': 'object',
'properties': {
'group_snapshots': {
'type': 'array',
'items': {
'type': 'object',
'properties': {
'id': {'type': 'string', 'format': 'uuid'},
'name': {'type': 'string'}
},
'additionalProperties': False,
'required': ['id', 'name'],
}
}
},
'additionalProperties': False,
'required': ['group_snapshots'],
}
}

list_group_snapshots_with_detail = {
'status_code': [200],
'response_body': {
'type': 'object',
'properties': {
'group_snapshots': {
'type': 'array',
'items': common_show_group_snapshot
}
},
'additionalProperties': False,
'required': ['group_snapshots'],
}
}

reset_group_snapshot_status = {'status_code': [202]}

+ 8
- 5
tempest/lib/services/volume/v3/group_snapshots_client.py View File

@@ -16,6 +16,7 @@
from oslo_serialization import jsonutils as json
from six.moves.urllib import parse as urllib

from tempest.lib.api_schema.response.volume import group_snapshots as schema
from tempest.lib.common import rest_client
from tempest.lib import exceptions as lib_exc
from tempest.lib.services.volume import base_client
@@ -34,7 +35,7 @@ class GroupSnapshotsClient(base_client.BaseClient):
post_body = json.dumps({'group_snapshot': kwargs})
resp, body = self.post('group_snapshots', post_body)
body = json.loads(body)
self.expected_success(202, resp.status)
self.validate_response(schema.create_group_snapshot, resp, body)
return rest_client.ResponseBody(resp, body)

def delete_group_snapshot(self, group_snapshot_id):
@@ -44,7 +45,7 @@ class GroupSnapshotsClient(base_client.BaseClient):
https://docs.openstack.org/api-ref/block-storage/v3/#delete-group-snapshot
"""
resp, body = self.delete('group_snapshots/%s' % group_snapshot_id)
self.expected_success(202, resp.status)
self.validate_response(schema.delete_group_snapshot, resp, body)
return rest_client.ResponseBody(resp, body)

def show_group_snapshot(self, group_snapshot_id):
@@ -56,7 +57,7 @@ class GroupSnapshotsClient(base_client.BaseClient):
url = "group_snapshots/%s" % str(group_snapshot_id)
resp, body = self.get(url)
body = json.loads(body)
self.expected_success(200, resp.status)
self.validate_response(schema.show_group_snapshot, resp, body)
return rest_client.ResponseBody(resp, body)

def list_group_snapshots(self, detail=False, **params):
@@ -67,13 +68,15 @@ class GroupSnapshotsClient(base_client.BaseClient):
https://docs.openstack.org/api-ref/block-storage/v3/#list-group-snapshots-with-details
"""
url = "group_snapshots"
list_group_snapshots = schema.list_group_snapshots_no_detail
if detail:
url += "/detail"
list_group_snapshots = schema.list_group_snapshots_with_detail
if params:
url += '?%s' % urllib.urlencode(params)
resp, body = self.get(url)
body = json.loads(body)
self.expected_success(200, resp.status)
self.validate_response(list_group_snapshots, resp, body)
return rest_client.ResponseBody(resp, body)

def reset_group_snapshot_status(self, group_snapshot_id, status_to_set):
@@ -85,7 +88,7 @@ class GroupSnapshotsClient(base_client.BaseClient):
post_body = json.dumps({'reset_status': {'status': status_to_set}})
resp, body = self.post('group_snapshots/%s/action' % group_snapshot_id,
post_body)
self.expected_success(202, resp.status)
self.validate_response(schema.reset_group_snapshot_status, resp, body)
return rest_client.ResponseBody(resp, body)

def is_resource_deleted(self, id):


Loading…
Cancel
Save