From ac2f6391e20a78c9fda4ef7503117b58ff50ef3d Mon Sep 17 00:00:00 2001 From: Ivan Kolodyazhny Date: Tue, 21 Jul 2020 18:21:21 +0300 Subject: [PATCH] Remove exception.Error class CinderException can be used as a low-level exception so we don't need to introduce one more wrapper for Exception. TSM backup driver modified without testing. Removed code was broken because it tried to use not existing Exception class attributes. Change-Id: Ie67d919f8f59572268f1f07946fb2d2f14a851f1 --- cinder/api/extensions.py | 3 ++- cinder/backup/drivers/tsm.py | 34 --------------------------------- cinder/exception.py | 4 ---- cinder/tests/unit/test_utils.py | 2 +- cinder/utils.py | 2 +- cinder/volume/throttling.py | 2 +- 6 files changed, 5 insertions(+), 42 deletions(-) diff --git a/cinder/api/extensions.py b/cinder/api/extensions.py index 09ab1dc7e87..800d38c730b 100644 --- a/cinder/api/extensions.py +++ b/cinder/api/extensions.py @@ -140,7 +140,8 @@ class ExtensionManager(object): LOG.debug('Loaded extension: %s', alias) if alias in self.extensions: - raise exception.Error("Found duplicate extension: %s" % alias) + raise exception.CinderException( + "Found duplicate extension: %s" % alias) self.extensions[alias] = ext def get_resources(self): diff --git a/cinder/backup/drivers/tsm.py b/cinder/backup/drivers/tsm.py index c0d1db58d09..795c0d08e1e 100644 --- a/cinder/backup/drivers/tsm.py +++ b/cinder/backup/drivers/tsm.py @@ -406,18 +406,6 @@ class TSMBackupDriver(driver.BackupDriver): 'err': exc.stderr}) LOG.error(err) raise exception.InvalidBackup(reason=err) - except exception.Error as exc: - err = (_('backup: %(vol_id)s failed to run dsmc ' - 'due to invalid arguments ' - 'on %(bpath)s.\n' - 'stdout: %(out)s\n stderr: %(err)s') - % {'vol_id': backup.volume_id, - 'bpath': backup_path, - 'out': exc.stdout, - 'err': exc.stderr}) - LOG.error(err) - raise exception.InvalidBackup(reason=err) - finally: _cleanup_device_hardlink(backup_path, volume_path, backup.volume_id) @@ -466,18 +454,6 @@ class TSMBackupDriver(driver.BackupDriver): 'err': exc.stderr}) LOG.error(err) raise exception.InvalidBackup(reason=err) - except exception.Error as exc: - err = (_('restore: %(vol_id)s failed to run dsmc ' - 'due to invalid arguments ' - 'on %(bpath)s.\n' - 'stdout: %(out)s\n stderr: %(err)s') - % {'vol_id': volume_id, - 'bpath': restore_path, - 'out': exc.stdout, - 'err': exc.stderr}) - LOG.error(err) - raise exception.InvalidBackup(reason=err) - finally: _cleanup_device_hardlink(restore_path, volume_path, volume_id) @@ -519,16 +495,6 @@ class TSMBackupDriver(driver.BackupDriver): 'err': exc.stderr}) LOG.error(err) raise exception.InvalidBackup(reason=err) - except exception.Error as exc: - err = (_('delete: %(vol_id)s failed to run dsmc ' - 'due to invalid arguments with ' - 'stdout: %(out)s\n stderr: %(err)s') - % {'vol_id': backup.volume_id, - 'out': exc.stdout, - 'err': exc.stderr}) - LOG.error(err) - raise exception.InvalidBackup(reason=err) - success = _check_dsmc_output(out, delete_attrs) if not success: # log error if tsm cannot delete the backup object diff --git a/cinder/exception.py b/cinder/exception.py index 6086b8a57cf..71ee5214b2f 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -57,10 +57,6 @@ class ConvertedException(webob.exc.WSGIHTTPException): super(ConvertedException, self).__init__() -class Error(Exception): - pass - - class CinderException(Exception): """Base Cinder Exception diff --git a/cinder/tests/unit/test_utils.py b/cinder/tests/unit/test_utils.py index 469506d0b3e..845f74a4223 100644 --- a/cinder/tests/unit/test_utils.py +++ b/cinder/tests/unit/test_utils.py @@ -517,7 +517,7 @@ class GetBlkdevMajorMinorTestCase(test.TestCase): @mock.patch('stat.S_ISBLK', return_value=False) def test_get_blkdev_failure(self, mock_isblk, mock_ischr, mock_stat): path = '/some/path' - self.assertRaises(exception.Error, + self.assertRaises(exception.CinderException, utils.get_blkdev_major_minor, path, lookup_for_file=False) mock_stat.assert_called_once_with(path) diff --git a/cinder/utils.py b/cinder/utils.py index 74f285a198f..0b75b663816 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -590,7 +590,7 @@ def get_blkdev_major_minor(path, lookup_for_file=True): return get_blkdev_major_minor(devpath, False) else: msg = _("Unable to get a block device for file \'%s\'") % path - raise exception.Error(msg) + raise exception.CinderException(msg) def check_string_length(value, name, min_length=0, max_length=None, diff --git a/cinder/volume/throttling.py b/cinder/volume/throttling.py index 3c6ddaa4cb6..b79a2d36bbd 100644 --- a/cinder/volume/throttling.py +++ b/cinder/volume/throttling.py @@ -75,7 +75,7 @@ class BlkioCgroup(Throttle): def _get_device_number(self, path): try: return utils.get_blkdev_major_minor(path) - except exception.Error as e: + except exception.CinderException as e: LOG.error('Failed to get device number for throttling: ' '%(error)s', {'error': e})