]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix dropped exception for create_export in vol manager
authorEric Harney <eharney@redhat.com>
Thu, 10 Apr 2014 16:57:50 +0000 (12:57 -0400)
committerEric Harney <eharney@redhat.com>
Thu, 26 Jun 2014 17:28:15 +0000 (17:28 +0000)
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

cinder/tests/test_volume.py
cinder/volume/manager.py

index 2873b5d18955c101cd36f01df9d0e64ab7bfb905..9784714e3e7594755628933a07d948d1aef31806 100644 (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"
index 30617a376de51071690b3e5fd13860dd5af33b10..fd6badebe61978a8abe6e6e70782486449f2f2a9 100644 (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)