api: Add schemas for share extend, shrink actions
Signed-off-by: Youssef <baataouiyoussef@gmail.com> Change-Id: Ic4d9a8de0916c5dbde00452e20f502a3eceea842 Co-authored-by: Stephen Finucane <stephenfin@redhat.com> Partially-implements: bp/json-schema-validation
This commit is contained in:
committed by
Stephen Finucane
parent
b558f75b09
commit
0ae5d257ab
@@ -10,6 +10,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
|
||||
from manila.api.validation import parameter_types
|
||||
|
||||
|
||||
soft_delete_request_body = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
@@ -32,6 +37,61 @@ restore_request_body = {
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
extend_request_body = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'os-extend': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'new_size': parameter_types.non_negative_integer,
|
||||
},
|
||||
'required': ['new_size'],
|
||||
# TODO(stephenfin): Set to False in a future microversion
|
||||
'additionalProperties': True,
|
||||
}
|
||||
},
|
||||
'required': ['os-extend'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
extend_request_body_v27 = copy.deepcopy(extend_request_body)
|
||||
extend_request_body_v27['properties']['extend'] = (
|
||||
extend_request_body_v27['properties'].pop('os-extend')
|
||||
)
|
||||
extend_request_body_v27['required'] = ['extend']
|
||||
|
||||
extend_request_body_v264 = copy.deepcopy(extend_request_body_v27)
|
||||
extend_request_body_v264['properties']['extend']['properties'].update({
|
||||
'force': parameter_types.boolean
|
||||
})
|
||||
|
||||
shrink_request_body = {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'os-shrink': {
|
||||
'type': 'object',
|
||||
'properties': {
|
||||
'new_size': parameter_types.non_negative_integer,
|
||||
},
|
||||
'required': ['new_size'],
|
||||
# TODO(stephenfin): Set to False in a future microversion
|
||||
'additionalProperties': True,
|
||||
}
|
||||
},
|
||||
'required': ['os-shrink'],
|
||||
'additionalProperties': False,
|
||||
}
|
||||
|
||||
shrink_request_body_v27 = copy.deepcopy(shrink_request_body)
|
||||
shrink_request_body_v27['properties']['shrink'] = (
|
||||
shrink_request_body_v27['properties'].pop('os-shrink')
|
||||
)
|
||||
shrink_request_body_v27['required'] = ['shrink']
|
||||
|
||||
soft_delete_response_body = {'type': 'null'}
|
||||
|
||||
restore_response_body = {'type': 'null'}
|
||||
|
||||
extend_response_body = {'type': 'null'}
|
||||
|
||||
shrink_response_body = {'type': 'null'}
|
||||
|
||||
@@ -548,32 +548,36 @@ class ShareController(wsgi.Controller,
|
||||
|
||||
@wsgi.Controller.api_version('2.0', '2.6')
|
||||
@wsgi.action('os-extend')
|
||||
@validation.request_body_schema(schema.extend_request_body)
|
||||
@validation.response_body_schema(schema.extend_response_body)
|
||||
def extend_legacy(self, req, id, body):
|
||||
"""Extend size of a share."""
|
||||
body.get('os-extend', {}).pop('force', None)
|
||||
return self._extend(req, id, body)
|
||||
|
||||
@wsgi.Controller.api_version('2.7', '2.63')
|
||||
@wsgi.Controller.api_version('2.7')
|
||||
@wsgi.action('extend')
|
||||
@validation.request_body_schema(schema.extend_request_body_v27, '2.7', '2.63') # noqa: E501
|
||||
@validation.request_body_schema(schema.extend_request_body_v264, '2.64')
|
||||
@validation.response_body_schema(schema.extend_response_body)
|
||||
def extend(self, req, id, body):
|
||||
"""Extend size of a share."""
|
||||
body.get('extend', {}).pop('force', None)
|
||||
return self._extend(req, id, body)
|
||||
|
||||
@wsgi.Controller.api_version('2.64') # noqa
|
||||
@wsgi.action('extend')
|
||||
def extend(self, req, id, body): # pylint: disable=function-redefined # noqa F811
|
||||
"""Extend size of a share."""
|
||||
if req.api_version_request < api_version.APIVersionRequest('2.64'):
|
||||
body.get('extend', {}).pop('force', None)
|
||||
return self._extend(req, id, body)
|
||||
|
||||
@wsgi.Controller.api_version('2.0', '2.6')
|
||||
@wsgi.action('os-shrink')
|
||||
@validation.request_body_schema(schema.shrink_request_body)
|
||||
@validation.response_body_schema(schema.shrink_response_body)
|
||||
def shrink_legacy(self, req, id, body):
|
||||
"""Shrink size of a share."""
|
||||
return self._shrink(req, id, body)
|
||||
|
||||
@wsgi.Controller.api_version('2.7')
|
||||
@wsgi.action('shrink')
|
||||
@validation.request_body_schema(schema.shrink_request_body_v27, '2.7')
|
||||
@validation.response_body_schema(schema.shrink_response_body)
|
||||
def shrink(self, req, id, body):
|
||||
"""Shrink size of a share."""
|
||||
return self._shrink(req, id, body)
|
||||
|
||||
@@ -2743,7 +2743,7 @@ class ShareActionsTest(test.TestCase):
|
||||
size = '2'
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v2/shares/%s/action' % id, version=version)
|
||||
actual_response = self.controller._extend(req, id, body)
|
||||
actual_response = self.controller._extend(req, id, body=body)
|
||||
|
||||
share_api.API.get.assert_called_once_with(mock.ANY, id)
|
||||
share_api.API.extend.assert_called_once_with(
|
||||
@@ -2758,7 +2758,7 @@ class ShareActionsTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/shares/%s/action' % id)
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller._extend, req, id, body)
|
||||
self.controller._extend, req, id, body=body)
|
||||
|
||||
@ddt.data({'source': exception.InvalidInput,
|
||||
'target': webob.exc.HTTPBadRequest},
|
||||
@@ -2774,7 +2774,7 @@ class ShareActionsTest(test.TestCase):
|
||||
self.mock_object(share_api.API, "extend",
|
||||
mock.Mock(side_effect=source('fake')))
|
||||
|
||||
self.assertRaises(target, self.controller._extend, req, id, body)
|
||||
self.assertRaises(target, self.controller._extend, req, id, body=body)
|
||||
|
||||
@ddt.unpack
|
||||
@ddt.data(
|
||||
@@ -2790,7 +2790,7 @@ class ShareActionsTest(test.TestCase):
|
||||
size = '1'
|
||||
req = fakes.HTTPRequest.blank(
|
||||
'/v2/shares/%s/action' % id, version=version)
|
||||
actual_response = self.controller._shrink(req, id, body)
|
||||
actual_response = self.controller._shrink(req, id, body=body)
|
||||
|
||||
share_api.API.get.assert_called_once_with(mock.ANY, id)
|
||||
share_api.API.shrink.assert_called_once_with(
|
||||
@@ -2805,7 +2805,7 @@ class ShareActionsTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v2/shares/%s/action' % id)
|
||||
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller._shrink, req, id, body)
|
||||
self.controller._shrink, req, id, body=body)
|
||||
|
||||
@ddt.data({'source': exception.InvalidInput,
|
||||
'target': webob.exc.HTTPBadRequest},
|
||||
@@ -2819,7 +2819,7 @@ class ShareActionsTest(test.TestCase):
|
||||
self.mock_object(share_api.API, "shrink",
|
||||
mock.Mock(side_effect=source('fake')))
|
||||
|
||||
self.assertRaises(target, self.controller._shrink, req, id, body)
|
||||
self.assertRaises(target, self.controller._shrink, req, id, body=body)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
|
||||
Reference in New Issue
Block a user