Merge "Fix 500 HTTP API error caused by rpcapi RemoteError exception"
This commit is contained in:
@@ -79,8 +79,9 @@ class VolumeActionsController(wsgi.Controller):
|
||||
except messaging.RemoteError as error:
|
||||
if error.exc_type in ['InvalidVolume', 'InvalidUUID',
|
||||
'InvalidVolumeAttachMode']:
|
||||
msg = "Error attaching volume - %(err_type)s: %(err_msg)s" % {
|
||||
'err_type': error.exc_type, 'err_msg': error.value}
|
||||
msg = _("Error attaching volume - %(err_type)s: "
|
||||
"%(err_msg)s") % {
|
||||
'err_type': error.exc_type, 'err_msg': error.value}
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
else:
|
||||
# There are also few cases where attach call could fail due to
|
||||
@@ -105,8 +106,9 @@ class VolumeActionsController(wsgi.Controller):
|
||||
self.volume_api.detach(context, volume, attachment_id)
|
||||
except messaging.RemoteError as error:
|
||||
if error.exc_type in ['VolumeAttachmentNotFound', 'InvalidVolume']:
|
||||
msg = "Error detaching volume - %(err_type)s: %(err_msg)s" % \
|
||||
{'err_type': error.exc_type, 'err_msg': error.value}
|
||||
msg = _("Error detaching volume - %(err_type)s: "
|
||||
"%(err_msg)s") % {
|
||||
'err_type': error.exc_type, 'err_msg': error.value}
|
||||
raise webob.exc.HTTPBadRequest(explanation=msg)
|
||||
else:
|
||||
# There are also few cases where detach call could fail due to
|
||||
@@ -177,6 +179,10 @@ class VolumeActionsController(wsgi.Controller):
|
||||
except exception.VolumeBackendAPIException:
|
||||
msg = _("Unable to fetch connection information from backend.")
|
||||
raise webob.exc.HTTPInternalServerError(explanation=msg)
|
||||
except messaging.RemoteError as error:
|
||||
if error.exc_type == 'InvalidInput':
|
||||
raise exception.InvalidInput(reason=error.value)
|
||||
raise
|
||||
|
||||
return {'connection_info': info}
|
||||
|
||||
|
||||
@@ -126,6 +126,21 @@ class VolumeActionsTest(test.TestCase):
|
||||
fake_auth_context=self.context))
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
@mock.patch('cinder.volume.rpcapi.VolumeAPI.initialize_connection')
|
||||
def test_initialize_connection_without_initiator(self,
|
||||
_init_connection):
|
||||
_init_connection.side_effect = messaging.RemoteError('InvalidInput')
|
||||
body = {'os-initialize_connection': {'connector': 'w/o_initiator'}}
|
||||
req = webob.Request.blank('/v2/%s/volumes/%s/action' %
|
||||
(fake.PROJECT_ID, fake.VOLUME_ID))
|
||||
req.method = "POST"
|
||||
req.body = jsonutils.dump_as_bytes(body)
|
||||
req.headers["content-type"] = "application/json"
|
||||
|
||||
res = req.get_response(fakes.wsgi_app(
|
||||
fake_auth_context=self.context))
|
||||
self.assertEqual(400, res.status_int)
|
||||
|
||||
def test_initialize_connection_exception(self):
|
||||
with mock.patch.object(volume_api.API,
|
||||
'initialize_connection') as init_conn:
|
||||
|
||||
Reference in New Issue
Block a user