Merge "Handle terminate_connection() exception in volume manager"
This commit is contained in:
commit
2d6a903823
@ -210,7 +210,11 @@ class VolumeActionsController(wsgi.Controller):
|
|||||||
connector = body['os-terminate_connection']['connector']
|
connector = body['os-terminate_connection']['connector']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise webob.exc.HTTPBadRequest("Must specify 'connector'")
|
raise webob.exc.HTTPBadRequest("Must specify 'connector'")
|
||||||
self.volume_api.terminate_connection(context, volume, connector)
|
try:
|
||||||
|
self.volume_api.terminate_connection(context, volume, connector)
|
||||||
|
except exception.VolumeBackendAPIException as error:
|
||||||
|
msg = _("Unable to terminate volume connection from backend.")
|
||||||
|
raise webob.exc.HTTPInternalServerError(explanation=msg)
|
||||||
return webob.Response(status_int=202)
|
return webob.Response(status_int=202)
|
||||||
|
|
||||||
@wsgi.response(202)
|
@wsgi.response(202)
|
||||||
|
@ -107,34 +107,44 @@ class VolumeActionsTest(test.TestCase):
|
|||||||
self.assertEqual(res.status_int, 500)
|
self.assertEqual(res.status_int, 500)
|
||||||
|
|
||||||
def test_terminate_connection(self):
|
def test_terminate_connection(self):
|
||||||
def fake_terminate_connection(*args, **kwargs):
|
with mock.patch.object(volume_api.API,
|
||||||
return {}
|
'terminate_connection') as terminate_conn:
|
||||||
self.stubs.Set(volume.API, 'terminate_connection',
|
terminate_conn.return_value = {}
|
||||||
fake_terminate_connection)
|
body = {'os-terminate_connection': {'connector': 'fake'}}
|
||||||
|
req = webob.Request.blank('/v2/fake/volumes/1/action')
|
||||||
|
req.method = "POST"
|
||||||
|
req.body = jsonutils.dumps(body)
|
||||||
|
req.headers["content-type"] = "application/json"
|
||||||
|
|
||||||
body = {'os-terminate_connection': {'connector': 'fake'}}
|
res = req.get_response(fakes.wsgi_app())
|
||||||
req = webob.Request.blank('/v2/fake/volumes/1/action')
|
self.assertEqual(res.status_int, 202)
|
||||||
req.method = "POST"
|
|
||||||
req.body = jsonutils.dumps(body)
|
|
||||||
req.headers["content-type"] = "application/json"
|
|
||||||
|
|
||||||
res = req.get_response(fakes.wsgi_app())
|
|
||||||
self.assertEqual(res.status_int, 202)
|
|
||||||
|
|
||||||
def test_terminate_connection_without_connector(self):
|
def test_terminate_connection_without_connector(self):
|
||||||
def fake_terminate_connection(*args, **kwargs):
|
with mock.patch.object(volume_api.API,
|
||||||
return {}
|
'terminate_connection') as terminate_conn:
|
||||||
self.stubs.Set(volume.API, 'terminate_connection',
|
terminate_conn.return_value = {}
|
||||||
fake_terminate_connection)
|
body = {'os-terminate_connection': {}}
|
||||||
|
req = webob.Request.blank('/v2/fake/volumes/1/action')
|
||||||
|
req.method = "POST"
|
||||||
|
req.body = jsonutils.dumps(body)
|
||||||
|
req.headers["content-type"] = "application/json"
|
||||||
|
|
||||||
body = {'os-terminate_connection': {}}
|
res = req.get_response(fakes.wsgi_app())
|
||||||
req = webob.Request.blank('/v2/fake/volumes/1/action')
|
self.assertEqual(res.status_int, 400)
|
||||||
req.method = "POST"
|
|
||||||
req.body = jsonutils.dumps(body)
|
|
||||||
req.headers["content-type"] = "application/json"
|
|
||||||
|
|
||||||
res = req.get_response(fakes.wsgi_app())
|
def test_terminate_connection_with_exception(self):
|
||||||
self.assertEqual(res.status_int, 400)
|
with mock.patch.object(volume_api.API,
|
||||||
|
'terminate_connection') as terminate_conn:
|
||||||
|
terminate_conn.side_effect = \
|
||||||
|
exception.VolumeBackendAPIException(data=None)
|
||||||
|
body = {'os-terminate_connection': {'connector': 'fake'}}
|
||||||
|
req = webob.Request.blank('/v2/fake/volumes/1/action')
|
||||||
|
req.method = "POST"
|
||||||
|
req.body = jsonutils.dumps(body)
|
||||||
|
req.headers["content-type"] = "application/json"
|
||||||
|
|
||||||
|
res = req.get_response(fakes.wsgi_app())
|
||||||
|
self.assertEqual(res.status_int, 500)
|
||||||
|
|
||||||
def test_attach_to_instance(self):
|
def test_attach_to_instance(self):
|
||||||
body = {'os-attach': {'instance_uuid': 'fake',
|
body = {'os-attach': {'instance_uuid': 'fake',
|
||||||
|
@ -750,7 +750,14 @@ class VolumeManager(manager.SchedulerDependentManager):
|
|||||||
The format of connector is the same as for initialize_connection.
|
The format of connector is the same as for initialize_connection.
|
||||||
"""
|
"""
|
||||||
volume_ref = self.db.volume_get(context, volume_id)
|
volume_ref = self.db.volume_get(context, volume_id)
|
||||||
self.driver.terminate_connection(volume_ref, connector, force=force)
|
try:
|
||||||
|
self.driver.terminate_connection(volume_ref,
|
||||||
|
connector, force=force)
|
||||||
|
except Exception as err:
|
||||||
|
err_msg = (_('Unable to terminate volume connection: %(err)s')
|
||||||
|
% {'err': str(err)})
|
||||||
|
LOG.error(err_msg)
|
||||||
|
raise exception.VolumeBackendAPIException(data=err_msg)
|
||||||
|
|
||||||
@utils.require_driver_initialized
|
@utils.require_driver_initialized
|
||||||
def accept_transfer(self, context, volume_id, new_user, new_project):
|
def accept_transfer(self, context, volume_id, new_user, new_project):
|
||||||
|
Loading…
Reference in New Issue
Block a user