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 commit b24ef91f2c)
(cherry picked from commit 2aa760011d)
(cherry picked from commit 7918f1d4bb)
(cherry picked from commit c0fc23a39f)
(cherry picked from commit 84111ad7cb)
This commit is contained in:
melakualehegn 2023-10-26 03:11:03 +03:00 committed by Goutham Pacha Ravi
parent d762766e43
commit ede80c4f36
4 changed files with 30 additions and 1 deletions

View File

@ -374,6 +374,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:

View File

@ -199,7 +199,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)

View File

@ -533,6 +533,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,

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Changed the error and status code that was raised
when share types are not handled in shares api