From b9e6af72029aebaa2b101cd9ade657a3c532b73d Mon Sep 17 00:00:00 2001 From: Michal Dulko Date: Wed, 1 Apr 2015 13:28:34 +0200 Subject: [PATCH] Catch more general exception in manager's create_volume 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 | 21 +++++++++++++++++++++ cinder/volume/manager.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index 68ca32ca1..71bcf4378 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -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') diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index bd728d1e5..69bb372e1 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -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 -- 2.45.2