Merge "Check if a exception has a code on it before read the code"
This commit is contained in:
@@ -307,6 +307,25 @@ class CinderApiTestCase(test.NoDBTestCase):
|
||||
mock_cinderclient.return_value.volumes. \
|
||||
initialize_connection.assert_called_once_with(volume_id, connector)
|
||||
|
||||
@mock.patch('nova.volume.cinder.LOG')
|
||||
@mock.patch('nova.volume.cinder.cinderclient')
|
||||
def test_initialize_connection_exception_no_code(
|
||||
self, mock_cinderclient, mock_log):
|
||||
mock_cinderclient.return_value.volumes. \
|
||||
initialize_connection.side_effect = (
|
||||
cinder_exception.ClientException(500, "500"))
|
||||
mock_cinderclient.return_value.volumes. \
|
||||
terminate_connection.side_effect = (
|
||||
test.TestingException)
|
||||
|
||||
connector = {'host': 'fakehost1'}
|
||||
self.assertRaises(cinder_exception.ClientException,
|
||||
self.api.initialize_connection,
|
||||
self.ctx,
|
||||
'id1',
|
||||
connector)
|
||||
self.assertIsNone(mock_log.error.call_args_list[1][0][1]['code'])
|
||||
|
||||
@mock.patch('nova.volume.cinder.cinderclient')
|
||||
def test_initialize_connection_rollback(self, mock_cinderclient):
|
||||
mock_cinderclient.return_value.volumes.\
|
||||
|
@@ -441,7 +441,8 @@ class API(object):
|
||||
{'vol': volume_id,
|
||||
'host': connector.get('host'),
|
||||
'msg': six.text_type(exc),
|
||||
'code': exc.code})
|
||||
'code': (
|
||||
exc.code if hasattr(exc, 'code') else None)})
|
||||
|
||||
@translate_volume_exception
|
||||
def terminate_connection(self, context, volume_id, connector):
|
||||
|
Reference in New Issue
Block a user