Merge "Add schema validation for show snapshot API and fix show controller"

This commit is contained in:
Zuul
2026-03-12 23:25:38 +00:00
committed by Gerrit Code Review
2 changed files with 138 additions and 15 deletions
+117
View File
@@ -12,6 +12,7 @@
import copy
from oslo_config import cfg
from manila.api.validation import helpers
from manila.api.validation import parameter_types
from manila.api.validation import response_types
@@ -120,6 +121,13 @@ index_request_query_v279['properties'].update({
}),
})
show_request_query = {
'type': 'object',
'properties': {},
'required': [],
'additionalProperties': True,
}
_snapshot_response = {
'type': 'object',
'properties': {
@@ -147,3 +155,112 @@ index_response_body = {
'required': ['snapshots'],
'additionalProperties': False,
}
show_snapshot = {
'type': 'object',
'properties': {
'id': {
'type': ['string', 'integer'],
'description': helpers.description('snapshot_id'),
},
'status': {
'type': 'string',
'description': helpers.description('snapshot_status'),
},
'share_id': {
'type': 'string',
'description': helpers.description('snapshot_share_id'),
},
'name': {
'type': ['string', 'null'],
'description': helpers.description('name'),
},
'description': {
'type': ['string', 'null'],
'description': helpers.description('description'),
},
'created_at': {
'type': 'string',
'description': helpers.description('created_at'),
},
'share_proto': {
'type': 'string',
'description': helpers.description('snapshot_share_protocol'),
},
'share_size': {
'type': ['integer', 'null'],
'description': helpers.description('snapshot_share_size'),
},
'size': {
'type': ['integer', 'null'],
'description': helpers.description('snapshot_size'),
},
'links': response_types.links,
},
'required': [
'id', 'status', 'share_id', 'name', 'description',
'created_at', 'share_proto', 'share_size', 'size', 'links',
],
'additionalProperties': False,
}
# >= v2.12: provider_location added
show_snapshot_v212 = copy.deepcopy(show_snapshot)
show_snapshot_v212['properties'].update({
'provider_location': {
'type': ['string', 'null'],
'description': helpers.description('snapshot_provider_location'),
},
})
# >= v2.17: project_id and user_id added
show_snapshot_v217 = copy.deepcopy(show_snapshot_v212)
show_snapshot_v217['properties'].update({
'project_id': {
'type': 'string',
'description': helpers.description('snapshot_project_id'),
},
'user_id': {
'type': 'string',
'description': helpers.description('snapshot_user_id'),
},
})
show_snapshot_v217['required'].extend(['project_id', 'user_id'])
# >= v2.73: metadata added
show_snapshot_v273 = copy.deepcopy(show_snapshot_v217)
show_snapshot_v273['properties'].update({
'metadata': {
'type': 'object',
'description': helpers.description('metadata'),
'additionalProperties': {'type': 'string'},
},
})
# Base show response
show_response = {
'type': 'object',
'properties': {
'snapshot': show_snapshot,
},
'required': ['snapshot'],
'additionalProperties': False,
}
# >= v2.12 show response
show_response_v212 = copy.deepcopy(show_response)
show_response_v212['properties'].update({
'snapshot': show_snapshot_v212,
})
# >= v2.17 show response
show_response_v217 = copy.deepcopy(show_response_v212)
show_response_v217['properties'].update({
'snapshot': show_snapshot_v217,
})
# >= v2.73 show response
show_response_v273 = copy.deepcopy(show_response_v217)
show_response_v273['properties'].update({
'snapshot': show_snapshot_v273,
})
+21 -15
View File
@@ -63,21 +63,6 @@ class ShareSnapshotsController(
def _delete(self, *args, **kwargs):
return self.share_api.delete_snapshot(*args, **kwargs)
def show(self, req, id):
"""Return data about the given snapshot."""
context = req.environ['manila.context']
try:
snapshot = self.share_api.get_snapshot(context, id)
# Snapshot with no instances is filtered out.
if snapshot.get('status') is None:
raise exc.HTTPNotFound()
except exception.NotFound:
raise exc.HTTPNotFound()
return self._view_builder.detail(req, snapshot)
def delete(self, req, id):
"""Delete a snapshot."""
context = req.environ['manila.context']
@@ -577,6 +562,27 @@ class ShareSnapshotsController(
req.GET.pop('description', None)
return self._get_snapshots(req, is_detail=True)
@wsgi.Controller.api_version("2.0")
@validation.request_query_schema(schema.show_request_query)
@validation.response_body_schema(schema.show_response, "2.0", "2.11")
@validation.response_body_schema(schema.show_response_v212, "2.12", "2.16")
@validation.response_body_schema(schema.show_response_v217, "2.17", "2.72")
@validation.response_body_schema(schema.show_response_v273, "2.73")
def show(self, req, id):
"""Return data about the given snapshot."""
context = req.environ['manila.context']
try:
snapshot = self.share_api.get_snapshot(context, id)
# Snapshot with no instances is filtered out.
if snapshot.get('status') is None:
raise exc.HTTPNotFound()
except exception.NotFound:
raise exc.HTTPNotFound()
return self._view_builder.detail(req, snapshot)
@wsgi.Controller.api_version("2.73")
@wsgi.Controller.authorize("get_metadata")
def index_metadata(self, req, resource_id):