Fix dropped exception for create_export in vol manager

If self.driver.create_export() fails, model_update is
False and this exception is therefore not logged,
causing things to break later in the execution path in
unexpected ways.

Closes-Bug: #1300148

Change-Id: I77600f3311efd71fa644adb6d65e4b19ab306203
This commit is contained in:
Eric Harney
2014-04-10 12:57:50 -04:00
parent e9ff57cc4d
commit 77b6a9f129
2 changed files with 39 additions and 5 deletions

View File

@@ -50,6 +50,7 @@ from cinder import quota
from cinder import test
from cinder.tests.brick.fake_lvm import FakeBrickLVM
from cinder.tests import conf_fixture
from cinder.tests import fake_driver
from cinder.tests import fake_notifier
from cinder.tests.image import fake as fake_image
from cinder.tests.keymgr import fake as fake_keymgr
@@ -1228,6 +1229,33 @@ class VolumeTestCase(BaseVolumeTestCase):
connector)
self.assertIsNone(conn_info['data']['qos_specs'])
@mock.patch.object(fake_driver.FakeISCSIDriver, 'create_export')
@mock.patch.object(db, 'volume_get')
@mock.patch.object(db, 'volume_update')
def test_initialize_connection_export_failure(self,
_mock_volume_get,
_mock_volume_update,
_mock_create_export):
"""Test exception path for create_export failure."""
_fake_admin_meta = {'fake-key': 'fake-value'}
_fake_volume = {'volume_type_id': 'fake_type_id',
'name': 'fake_name',
'host': 'fake_host',
'id': 'fake_volume_id',
'volume_admin_metadata': _fake_admin_meta}
_mock_volume_get.return_value = _fake_volume
_mock_volume_update.return_value = _fake_volume
_mock_create_export.side_effect = exception.CinderException
connector = {'ip': 'IP', 'initiator': 'INITIATOR'}
self.assertRaises(exception.VolumeBackendAPIException,
self.volume.initialize_connection,
self.context,
'fake_volume_id',
connector)
def test_run_attach_detach_volume_for_instance(self):
"""Make sure volume can be attached and detached from instance."""
mountpoint = "/dev/sdf"

View File

@@ -791,16 +791,22 @@ class VolumeManager(manager.SchedulerDependentManager):
LOG.debug("Volume %s: creating export", volume_id)
model_update = self.driver.create_export(context.elevated(),
volume)
except exception.CinderException:
err_msg = (_('Unable to create export for volume %(volume_id)s') %
{'volume_id': volume_id})
LOG.exception(err_msg)
raise exception.VolumeBackendAPIException(data=err_msg)
try:
if model_update:
volume = self.db.volume_update(context,
volume_id,
model_update)
except exception.CinderException as ex:
if model_update:
LOG.exception(_("Failed updating model of volume %(volume_id)s"
" with driver provided model %(model)s") %
{'volume_id': volume_id, 'model': model_update})
raise exception.ExportFailure(reason=ex)
LOG.exception(_("Failed updating model of volume %(volume_id)s"
" with driver provided model %(model)s") %
{'volume_id': volume_id, 'model': model_update})
raise exception.ExportFailure(reason=ex)
try:
conn_info = self.driver.initialize_connection(volume, connector)