api: Add schemas for share soft_delete, restore actions
Signed-off-by: Evan Tatavitto <evantatavitto@gmail.com> Change-Id: I4fe7863af304eff4a9a3903718de593faaecf46e Co-authored-by: Stephen Finucane <stephenfin@redhat.com> Partially-implements: bp/json-schema-validation
This commit is contained in:
committed by
Stephen Finucane
parent
3d8fbfe7bf
commit
b558f75b09
37
manila/api/schemas/shares.py
Normal file
37
manila/api/schemas/shares.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# 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.
|
||||
|
||||
soft_delete_request_body = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
# TODO(stephenfin): We should restrict this to 'null' in a future
|
||||
# microversion
|
||||
'soft_delete': {},
|
||||
},
|
||||
'required': ['soft_delete'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
restore_request_body = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
# TODO(stephenfin): We should restrict this to 'null' in a future
|
||||
# microversion
|
||||
'restore': {},
|
||||
},
|
||||
'required': ['restore'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
soft_delete_response_body = {'type': 'null'}
|
||||
|
||||
restore_response_body = {'type': 'null'}
|
||||
@@ -23,10 +23,12 @@ from webob import exc
|
||||
from manila.api import common
|
||||
from manila.api.openstack import api_version_request as api_version
|
||||
from manila.api.openstack import wsgi
|
||||
from manila.api.schemas import shares as schema
|
||||
from manila.api.v1 import share_manage
|
||||
from manila.api.v1 import share_unmanage
|
||||
from manila.api.v1 import shares
|
||||
from manila.api.v2 import metadata
|
||||
from manila.api import validation
|
||||
from manila.api.views import share_accesses as share_access_views
|
||||
from manila.api.views import share_migration as share_migration_views
|
||||
from manila.api.views import shares as share_views
|
||||
@@ -291,6 +293,8 @@ class ShareController(wsgi.Controller,
|
||||
@wsgi.Controller.api_version('2.69')
|
||||
@wsgi.action('soft_delete')
|
||||
@wsgi.Controller.authorize('soft_delete')
|
||||
@validation.request_body_schema(schema.soft_delete_request_body)
|
||||
@validation.response_body_schema(schema.soft_delete_response_body)
|
||||
def share_soft_delete(self, req, id, body):
|
||||
"""Soft delete a share."""
|
||||
context = req.environ['manila.context']
|
||||
@@ -314,6 +318,8 @@ class ShareController(wsgi.Controller,
|
||||
@wsgi.Controller.api_version('2.69')
|
||||
@wsgi.action('restore')
|
||||
@wsgi.Controller.authorize("restore")
|
||||
@validation.request_body_schema(schema.restore_request_body)
|
||||
@validation.response_body_schema(schema.restore_response_body)
|
||||
def share_restore(self, req, id, body):
|
||||
"""Restore a share from recycle bin."""
|
||||
context = req.environ['manila.context']
|
||||
|
||||
@@ -1694,7 +1694,7 @@ class ShareAPITest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/shares/1/action',
|
||||
version='2.69')
|
||||
body = {"soft_delete": None}
|
||||
resp = self.controller.share_soft_delete(req, 1, body)
|
||||
resp = self.controller.share_soft_delete(req, 1, body=body)
|
||||
self.assertEqual(202, resp.status_int)
|
||||
|
||||
def test_share_soft_delete_has_been_soft_deleted_already(self):
|
||||
@@ -1709,7 +1709,7 @@ class ShareAPITest(test.TestCase):
|
||||
|
||||
self.assertRaises(
|
||||
webob.exc.HTTPForbidden, self.controller.share_soft_delete,
|
||||
req, 1, body)
|
||||
req, 1, body=body)
|
||||
|
||||
def test_share_soft_delete_has_replicas(self):
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/shares/1/action',
|
||||
@@ -1722,7 +1722,7 @@ class ShareAPITest(test.TestCase):
|
||||
|
||||
self.assertRaises(
|
||||
webob.exc.HTTPConflict, self.controller.share_soft_delete,
|
||||
req, 1, body)
|
||||
req, 1, body=body)
|
||||
|
||||
def test_share_restore(self):
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/shares/1/action',
|
||||
@@ -1730,7 +1730,7 @@ class ShareAPITest(test.TestCase):
|
||||
body = {"restore": None}
|
||||
self.mock_object(share_api.API, 'get',
|
||||
mock.Mock(return_value=self.share_in_recycle_bin))
|
||||
resp = self.controller.share_restore(req, 1, body)
|
||||
resp = self.controller.share_restore(req, 1, body=body)
|
||||
self.assertEqual(202, resp.status_int)
|
||||
|
||||
def test_share_restore_with_deleting_status(self):
|
||||
@@ -1742,7 +1742,7 @@ class ShareAPITest(test.TestCase):
|
||||
mock.Mock(return_value=self.share_in_recycle_bin_is_deleting))
|
||||
self.assertRaises(
|
||||
webob.exc.HTTPForbidden, self.controller.share_restore,
|
||||
req, 1, body)
|
||||
req, 1, body=body)
|
||||
|
||||
def test_share_delete(self):
|
||||
req = fakes.HTTPRequest.blank('/v2/fake/shares/1')
|
||||
|
||||
Reference in New Issue
Block a user