]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Catch more general exception in manager's create_volume
authorMichal Dulko <michal.dulko@intel.com>
Wed, 1 Apr 2015 11:28:34 +0000 (13:28 +0200)
committerMichal Dulko <michal.dulko@intel.com>
Wed, 1 Apr 2015 11:28:34 +0000 (13:28 +0200)
When fixing issues with inaccurate allocated_capacity tracking when
create_volume flow fails (Icd6b04ac60c17cbda225d3be8bcc4435ea0cd7a8)
it was ignored that drivers may raise all kinds of exceptions and these
aren't repacked into CinderException in the flow. This commit broadens
except clause to catch Exception when deciding if rescheduling
occurred while creating a volume. Also regression unit test is added.

Change-Id: I36058eacd1eb6b42c6a4311bd3382ddc9f47550c
Closes-Bug: 1438744

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

index 68ca32ca1b59e546296ba78016b6c64870ef4293..71bcf437889e4177cd295fa795ac2b1e7f1a8775 100644 (file)
@@ -416,6 +416,27 @@ class VolumeTestCase(BaseVolumeTestCase):
 
         db.volume_destroy(context.get_admin_context(), volume_id)
 
+    def test_create_non_cinder_exception_rescheduling(self):
+        params = self.volume_params
+        del params['host']
+        volume = tests_utils.create_volume(
+            self.context,
+            availability_zone=CONF.storage_availability_zone,
+            **params)
+
+        volume_id = volume['id']
+        with mock.patch.object(self.volume.driver, 'create_volume',
+                               side_effect=processutils.ProcessExecutionError):
+            self.assertRaises(processutils.ProcessExecutionError,
+                              self.volume.create_volume,
+                              self.context, volume_id,
+                              {'volume_properties': params})
+        # NOTE(dulek): Volume should be rescheduled as we passed request_spec,
+        # assert that it wasn't counted in allocated_capacity tracking.
+        self.assertEqual(self.volume.stats['pools'], {})
+
+        db.volume_destroy(context.get_admin_context(), volume_id)
+
     @mock.patch.object(QUOTAS, 'rollback')
     @mock.patch.object(QUOTAS, 'commit')
     @mock.patch.object(QUOTAS, 'reserve')
index bd728d1e5aaff2626fe7576c5ee398320a405111..69bb372e1cf4d8875934320c58cd102617fb32d3 100644 (file)
@@ -467,7 +467,7 @@ class VolumeManager(manager.SchedulerDependentManager):
                 _run_flow()
             else:
                 _run_flow_locked()
-        except exception.CinderException as e:
+        except Exception as e:
             if hasattr(e, 'rescheduled'):
                 rescheduled = e.rescheduled
             raise