Change status and error handling for /shares API
This change modifies the status and error handling logic of the /shares API when it fails to handle the specified share_type in the request. The updated logic ensures that appropriate responses are generated to handle this scenario effectively. Closes-Bug: #1944478 Change-Id: I8d4b30daae2fe8c88c30d93d402bf2e5a558f804 (cherry picked from commitb24ef91f2c
) (cherry picked from commit2aa760011d
) (cherry picked from commit7918f1d4bb
) (cherry picked from commitc0fc23a39f
)
This commit is contained in:
parent
e0714acdfa
commit
84111ad7cb
@ -392,6 +392,8 @@ class ShareMixin(object):
|
||||
exception.ShareTypeNotFoundByName):
|
||||
msg = _("Share type not found.")
|
||||
raise exc.HTTPNotFound(explanation=msg)
|
||||
except exception.InvalidShareType as e:
|
||||
raise exc.HTTPBadRequest(explanation=e.message)
|
||||
elif not snapshot:
|
||||
def_share_type = share_types.get_default_share_type()
|
||||
if def_share_type:
|
||||
|
@ -198,7 +198,9 @@ def get_share_type_by_name(context, name):
|
||||
if name is None:
|
||||
msg = _("name cannot be None")
|
||||
raise exception.InvalidShareType(reason=msg)
|
||||
|
||||
if not isinstance(name, str):
|
||||
msg = _("the share type's name parameter was badly formatted")
|
||||
raise exception.InvalidShareType(reason=msg)
|
||||
return db.share_type_get_by_name(context, name)
|
||||
|
||||
|
||||
|
@ -542,6 +542,26 @@ class ShareAPITest(test.TestCase):
|
||||
self.mock_policy_check.assert_called_once_with(
|
||||
req.environ['manila.context'], self.resource_name, 'create')
|
||||
|
||||
def test_share_creation_fails_with_invalid_share_type(self):
|
||||
shr = {
|
||||
"size": 1,
|
||||
"name": "Share Test Name",
|
||||
"description": "Share Test Desc",
|
||||
"share_proto": "fakeproto",
|
||||
"availability_zone": "zone1:host1",
|
||||
"share_type": "Invalid share type"
|
||||
}
|
||||
body = {"share": shr}
|
||||
req = fakes.HTTPRequest.blank('/fake/shares')
|
||||
with mock.patch('manila.share.share_types.get_share_type_by_name',
|
||||
side_effect=exception.InvalidShareType(reason='')):
|
||||
self.assertRaises(webob.exc.HTTPBadRequest,
|
||||
self.controller.create,
|
||||
req,
|
||||
body)
|
||||
self.mock_policy_check.assert_called_once_with(
|
||||
req.environ['manila.context'], self.resource_name, 'create')
|
||||
|
||||
def test_share_create_invalid_availability_zone(self):
|
||||
self.mock_object(
|
||||
db,
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Changed the error and status code that was raised
|
||||
when share types are not handled in shares api
|
Loading…
Reference in New Issue
Block a user