From: Eric Harney Date: Thu, 10 Apr 2014 16:57:50 +0000 (-0400) Subject: Fix dropped exception for create_export in vol manager X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=77b6a9f129977799bc5c6ccec6caaf707fa3047c;p=openstack-build%2Fcinder-build.git 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 --- diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 2873b5d18..9784714e3 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -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" diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index 30617a376..fd6badebe 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -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)