From: Zhongyue Luo Date: Mon, 19 Aug 2013 07:39:00 +0000 (+0800) Subject: Removes exception instance creation on execute() X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3f54b6c053cfa464ad6d9e8883563d29dd6dfa1f;p=openstack-build%2Fcinder-build.git Removes exception instance creation on execute() For every excption raised in utils.execute(), a new instance is created. This patch removes this redundant step and directly uses exceptions defined in Oslo. Change-Id: I1425d7f1d69a8fde8fde29444fae4d12d045b730 --- diff --git a/cinder/backup/drivers/ceph.py b/cinder/backup/drivers/ceph.py index f63eb35a6..01a5ec21f 100644 --- a/cinder/backup/drivers/ceph.py +++ b/cinder/backup/drivers/ceph.py @@ -49,6 +49,7 @@ import time from cinder.backup.driver import BackupDriver from cinder import exception from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import units from cinder import utils import cinder.volume.drivers as drivers @@ -383,8 +384,8 @@ class CephBackupDriver(BackupDriver): cmd.extend([path, '-']) try: out, err = self._execute(*cmd) - except (exception.ProcessExecutionError, - exception.UnknownArgumentError) as exc: + except (processutils.ProcessExecutionError, + processutils.UnknownArgumentError) as exc: LOG.info(_("rbd export-diff failed - %s") % (str(exc))) raise exception.BackupRBDOperationFailed("rbd export-diff failed") @@ -392,8 +393,8 @@ class CephBackupDriver(BackupDriver): cmd.extend(['-', self._utf8("%s/%s" % (dest_pool, dest_name))]) try: out, err = self._execute(*cmd, process_input=out) - except (exception.ProcessExecutionError, - exception.UnknownArgumentError) as exc: + except (processutils.ProcessExecutionError, + processutils.UnknownArgumentError) as exc: LOG.info(_("rbd import-diff failed - %s") % (str(exc))) raise exception.BackupRBDOperationFailed("rbd import-diff failed") diff --git a/cinder/backup/drivers/tsm.py b/cinder/backup/drivers/tsm.py index 84f90f494..534c3a8a4 100644 --- a/cinder/backup/drivers/tsm.py +++ b/cinder/backup/drivers/tsm.py @@ -27,11 +27,13 @@ Cinder host for using TSM. import os import stat +from oslo.config import cfg + from cinder.backup.driver import BackupDriver from cinder import exception from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import utils -from oslo.config import cfg LOG = logging.getLogger(__name__) @@ -79,7 +81,7 @@ class TSMBackupDriver(BackupDriver): utils.execute('ln', volume_path, backup_path, run_as_root=True, check_exit_code=True) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: err = (_('backup: %(vol_id)s Failed to create device hardlink ' 'from %(vpath)s to %(bpath)s.\n' 'stdout: %(out)s\n stderr: %(err)s') @@ -254,7 +256,7 @@ class TSMBackupDriver(BackupDriver): '-f', hardlink_path, run_as_root=True) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: err = (_('backup: %(vol_id)s Failed to remove backup hardlink' ' from %(vpath)s to %(bpath)s.\n' 'stdout: %(out)s\n stderr: %(err)s') @@ -292,7 +294,7 @@ class TSMBackupDriver(BackupDriver): volume_id) try: self._do_backup(backup_path, volume_id) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: err = (_('backup: %(vol_id)s Failed to run dsmc ' 'on %(bpath)s.\n' 'stdout: %(out)s\n stderr: %(err)s') @@ -346,7 +348,7 @@ class TSMBackupDriver(BackupDriver): try: self._do_restore(restore_path, volume_id) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: err = (_('restore: %(vol_id)s Failed to run dsmc ' 'on %(bpath)s.\n' 'stdout: %(out)s\n stderr: %(err)s') @@ -407,7 +409,7 @@ class TSMBackupDriver(BackupDriver): run_as_root=True, check_exit_code=False) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: err = (_('delete: %(vol_id)s Failed to run dsmc with ' 'stdout: %(out)s\n stderr: %(err)s') % {'vol_id': volume_id, diff --git a/cinder/exception.py b/cinder/exception.py index b7888242d..cca4aa2c2 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -53,14 +53,6 @@ class ConvertedException(webob.exc.WSGIHTTPException): super(ConvertedException, self).__init__() -class ProcessExecutionError(processutils.ProcessExecutionError): - pass - - -class UnknownArgumentError(processutils.UnknownArgumentError): - pass - - class Error(Exception): pass diff --git a/cinder/tests/fake_utils.py b/cinder/tests/fake_utils.py index f4da47d78..fd44d6771 100644 --- a/cinder/tests/fake_utils.py +++ b/cinder/tests/fake_utils.py @@ -22,6 +22,7 @@ from eventlet import greenthread from cinder import exception from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import utils LOG = logging.getLogger(__name__) @@ -92,7 +93,7 @@ def fake_execute(*cmd_parts, **kwargs): attempts=attempts, run_as_root=run_as_root, check_exit_code=check_exit_code) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: LOG.debug(_('Faked command raised an exception %s'), e) raise diff --git a/cinder/tests/test_backup_ceph.py b/cinder/tests/test_backup_ceph.py index 2dd69ace1..51de25158 100644 --- a/cinder/tests/test_backup_ceph.py +++ b/cinder/tests/test_backup_ceph.py @@ -26,6 +26,7 @@ from cinder import context from cinder import db from cinder import exception from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import test from cinder.tests.backup.fake_rados import mock_rados from cinder.tests.backup.fake_rados import mock_rbd @@ -46,7 +47,7 @@ class BackupCephTestCase(test.TestCase): return db.backup_create(self.ctxt, backup)['id'] def fake_execute_w_exception(*args, **kwargs): - raise exception.ProcessExecutionError() + raise processutils.ProcessExecutionError() def time_inc(self): self.counter += 1 diff --git a/cinder/tests/test_backup_tsm.py b/cinder/tests/test_backup_tsm.py index f7a74252e..37d528fcf 100644 --- a/cinder/tests/test_backup_tsm.py +++ b/cinder/tests/test_backup_tsm.py @@ -26,6 +26,7 @@ from cinder import context from cinder import db from cinder import exception from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils as putils from cinder import test from cinder import utils @@ -143,10 +144,10 @@ class TSMBackupSimulator: kwargs = self._cmd_to_dict(cmd) if kwargs['cmd'] != 'dsmc' or kwargs['type'] not in cmd_switch: - raise exception.ProcessExecutionError(exit_code=1, - stdout='', - stderr='Not dsmc command', - cmd=' '.join(cmd)) + raise putils.ProcessExecutionError(exit_code=1, + stdout='', + stderr='Not dsmc command', + cmd=' '.join(cmd)) out, err, ret = cmd_switch[kwargs['type']](**kwargs) return (out, err, ret) @@ -178,10 +179,10 @@ class TSMBackupSimulator: err = '' ret = 0 else: - raise exception.ProcessExecutionError(exit_code=1, - stdout='', - stderr='Unsupported command', - cmd=' '.join(cmd)) + raise putils.ProcessExecutionError(exit_code=1, + stdout='', + stderr='Unsupported command', + cmd=' '.join(cmd)) return (out, err, ret) def error_injection(self, cmd, error): @@ -195,7 +196,7 @@ def fake_exec(*cmd, **kwargs): out, err, ret = SIM.exec_cmd(cmd) if ret and check_exit_code: - raise exception.ProcessExecutionError( + raise putils.ProcessExecutionError( exit_code=-1, stdout=out, stderr=err, diff --git a/cinder/tests/test_glusterfs.py b/cinder/tests/test_glusterfs.py index 2715172cc..39c9da5af 100644 --- a/cinder/tests/test_glusterfs.py +++ b/cinder/tests/test_glusterfs.py @@ -28,7 +28,7 @@ import json from cinder import context from cinder import exception -from cinder.exception import ProcessExecutionError +from cinder.openstack.common import processutils as putils from cinder import test from cinder import units from cinder.volume import configuration as conf @@ -129,7 +129,7 @@ class GlusterFsDriverTestCase(test.TestCase): drv._execute('mkdir', '-p', self.TEST_MNT_POINT) drv._execute('mount', '-t', 'glusterfs', self.TEST_EXPORT1, self.TEST_MNT_POINT, run_as_root=True).\ - AndRaise(ProcessExecutionError( + AndRaise(putils.ProcessExecutionError( stderr='is busy or already mounted')) mox.ReplayAll() @@ -155,12 +155,12 @@ class GlusterFsDriverTestCase(test.TestCase): self.TEST_EXPORT1, self.TEST_MNT_POINT, run_as_root=True). \ - AndRaise(ProcessExecutionError(stderr='is busy or ' - 'already mounted')) + AndRaise(putils.ProcessExecutionError(stderr='is busy or ' + 'already mounted')) mox.ReplayAll() - self.assertRaises(ProcessExecutionError, drv._mount_glusterfs, + self.assertRaises(putils.ProcessExecutionError, drv._mount_glusterfs, self.TEST_EXPORT1, self.TEST_MNT_POINT, ensure=False) diff --git a/cinder/tests/test_gpfs.py b/cinder/tests/test_gpfs.py index f486380c8..398092b3c 100644 --- a/cinder/tests/test_gpfs.py +++ b/cinder/tests/test_gpfs.py @@ -25,6 +25,7 @@ from cinder import exception from cinder.image import image_utils from cinder.openstack.common import importutils from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import test from cinder import utils from cinder.volume import configuration as conf @@ -476,7 +477,7 @@ class GPFSDriverTestCase(test.TestCase): pass def _fake_is_not_gpfs_path(self, path): - raise(exception.ProcessExecutionError('invalid gpfs path')) + raise(processutils.ProcessExecutionError('invalid gpfs path')) def _fake_convert_image(self, source, dest, out_format): utils.execute('cp', source, dest) diff --git a/cinder/tests/test_nfs.py b/cinder/tests/test_nfs.py index 0609550a5..f971749d6 100644 --- a/cinder/tests/test_nfs.py +++ b/cinder/tests/test_nfs.py @@ -29,7 +29,7 @@ from mox import stubout from cinder import context from cinder import exception -from cinder.exception import ProcessExecutionError +from cinder.openstack.common import processutils as putils from cinder import test from cinder import units @@ -228,7 +228,7 @@ class NfsDriverTestCase(test.TestCase): drv._execute('mkdir', '-p', self.TEST_MNT_POINT) drv._execute('mount', '-t', 'nfs', self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT, run_as_root=True).\ - AndRaise(ProcessExecutionError( + AndRaise(putils.ProcessExecutionError( stderr='is busy or already mounted')) mox.ReplayAll() @@ -250,12 +250,12 @@ class NfsDriverTestCase(test.TestCase): '-t', 'nfs', self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT, run_as_root=True).\ - AndRaise(ProcessExecutionError(stderr='is busy or ' - 'already mounted')) + AndRaise(putils.ProcessExecutionError(stderr='is busy or ' + 'already mounted')) mox.ReplayAll() - self.assertRaises(ProcessExecutionError, drv._mount_nfs, + self.assertRaises(putils.ProcessExecutionError, drv._mount_nfs, self.TEST_NFS_EXPORT1, self.TEST_MNT_POINT, ensure=False) diff --git a/cinder/tests/test_sheepdog.py b/cinder/tests/test_sheepdog.py index b41026657..51428399d 100644 --- a/cinder/tests/test_sheepdog.py +++ b/cinder/tests/test_sheepdog.py @@ -22,6 +22,7 @@ import tempfile from cinder import exception from cinder.image import image_utils +from cinder.openstack.common import processutils from cinder import test from cinder import units from cinder.volume.drivers.sheepdog import SheepdogDriver @@ -79,7 +80,7 @@ class SheepdogTestCase(test.TestCase): def test_update_volume_stats_error(self): def fake_stats(*args): - raise exception.ProcessExecutionError() + raise processutils.ProcessExecutionError() self.stubs.Set(self.driver, '_execute', fake_stats) expected = dict( volume_backend_name='sheepdog', diff --git a/cinder/tests/test_storwize_svc.py b/cinder/tests/test_storwize_svc.py index b2a4949e5..1836db9b7 100644 --- a/cinder/tests/test_storwize_svc.py +++ b/cinder/tests/test_storwize_svc.py @@ -33,6 +33,7 @@ from cinder import context from cinder import exception from cinder.openstack.common import excutils from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import test from cinder import units from cinder import utils @@ -1229,10 +1230,10 @@ port_speed!N/A out, err = ('', 'ERROR: Unsupported command') if (check_exit_code) and (len(err) != 0): - raise exception.ProcessExecutionError(exit_code=1, - stdout=out, - stderr=err, - cmd=' '.join(cmd)) + raise processutils.ProcessExecutionError(exit_code=1, + stdout=out, + stderr=err, + cmd=' '.join(cmd)) return (out, err) @@ -1257,7 +1258,7 @@ class StorwizeSVCFakeDriver(storwize_svc.StorwizeSVCDriver): LOG.debug(_('CLI output:\n stdout: %(stdout)s\n stderr: ' '%(stderr)s') % {'stdout': stdout, 'stderr': stderr}) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: with excutils.save_and_reraise_exception(): LOG.debug(_('CLI Exception output:\n stdout: %(out)s\n ' 'stderr: %(err)s') % {'out': e.stdout, @@ -1441,10 +1442,10 @@ class StorwizeSVCDriverTestCase(test.TestCase): return attrs def _fail_prepare_fc_map(self, fc_map_id, source, target): - raise exception.ProcessExecutionError(exit_code=1, - stdout='', - stderr='unit-test-fail', - cmd='prestartfcmap id') + raise processutils.ProcessExecutionError(exit_code=1, + stdout='', + stderr='unit-test-fail', + cmd='prestartfcmap id') def test_storwize_svc_snapshots(self): vol1 = self._generate_vol_info(None, None) @@ -1462,18 +1463,18 @@ class StorwizeSVCDriverTestCase(test.TestCase): # Test prestartfcmap, startfcmap, and rmfcmap failing orig = self.driver._call_prepare_fc_map self.driver._call_prepare_fc_map = self._fail_prepare_fc_map - self.assertRaises(exception.ProcessExecutionError, + self.assertRaises(processutils.ProcessExecutionError, self.driver.create_snapshot, snap1) self.driver._call_prepare_fc_map = orig if self.USESIM: self.sim.error_injection('lsfcmap', 'speed_up') self.sim.error_injection('startfcmap', 'bad_id') - self.assertRaises(exception.ProcessExecutionError, + self.assertRaises(processutils.ProcessExecutionError, self.driver.create_snapshot, snap1) self._assert_vol_exists(snap1['name'], False) self.sim.error_injection('prestartfcmap', 'bad_id') - self.assertRaises(exception.ProcessExecutionError, + self.assertRaises(processutils.ProcessExecutionError, self.driver.create_snapshot, snap1) self._assert_vol_exists(snap1['name'], False) @@ -1512,7 +1513,7 @@ class StorwizeSVCDriverTestCase(test.TestCase): # Fail the snapshot orig = self.driver._call_prepare_fc_map self.driver._call_prepare_fc_map = self._fail_prepare_fc_map - self.assertRaises(exception.ProcessExecutionError, + self.assertRaises(processutils.ProcessExecutionError, self.driver.create_volume_from_snapshot, vol2, snap1) self.driver._call_prepare_fc_map = orig @@ -1574,7 +1575,7 @@ class StorwizeSVCDriverTestCase(test.TestCase): self.assertEqual(attributes['mdisk_grp_name'], pool) # Try to create the volume again (should fail) - self.assertRaises(exception.ProcessExecutionError, + self.assertRaises(processutils.ProcessExecutionError, self.driver.create_volume, volume) @@ -1637,7 +1638,7 @@ class StorwizeSVCDriverTestCase(test.TestCase): self.assertNotEqual(attrs[k], v) else: self.assertEqual(attrs[k], v) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: if 'CMMVC7050E' not in e.stderr: raise @@ -1753,7 +1754,7 @@ class StorwizeSVCDriverTestCase(test.TestCase): self.driver.initialize_connection(volume1, self._connector) # Try to delete the 1st volume (should fail because it is mapped) - self.assertRaises(exception.ProcessExecutionError, + self.assertRaises(processutils.ProcessExecutionError, self.driver.delete_volume, volume1) @@ -1892,7 +1893,7 @@ class StorwizeSVCDriverTestCase(test.TestCase): if self.USESIM and False: snap = self._generate_vol_info(master['name'], master['id']) self.sim.error_injection('startfcmap', 'bad_id') - self.assertRaises(exception.ProcessExecutionError, + self.assertRaises(processutils.ProcessExecutionError, self.driver.create_snapshot, snap) self._assert_vol_exists(snap['name'], False) @@ -1915,7 +1916,7 @@ class StorwizeSVCDriverTestCase(test.TestCase): volfs = self._generate_vol_info(None, None) self.sim.error_injection('startfcmap', 'bad_id') self.sim.error_injection('lsfcmap', 'speed_up') - self.assertRaises(exception.ProcessExecutionError, + self.assertRaises(processutils.ProcessExecutionError, self.driver.create_volume_from_snapshot, volfs, snap) self._assert_vol_exists(volfs['name'], False) @@ -1942,7 +1943,7 @@ class StorwizeSVCDriverTestCase(test.TestCase): clone = self._generate_vol_info(None, None) self.sim.error_injection('startfcmap', 'bad_id') self.sim.error_injection('lsfcmap', 'speed_up') - self.assertRaises(exception.ProcessExecutionError, + self.assertRaises(processutils.ProcessExecutionError, self.driver.create_cloned_volume, clone, volfs) self._assert_vol_exists(clone['name'], False) diff --git a/cinder/tests/test_utils.py b/cinder/tests/test_utils.py index 7a6c4b4be..db97ec3b8 100644 --- a/cinder/tests/test_utils.py +++ b/cinder/tests/test_utils.py @@ -69,7 +69,7 @@ exit 1 ''') fp.close() os.chmod(tmpfilename, 0o755) - self.assertRaises(exception.ProcessExecutionError, + self.assertRaises(putils.ProcessExecutionError, utils.execute, tmpfilename, tmpfilename2, attempts=10, process_input='foo', @@ -88,14 +88,14 @@ exit 1 os.unlink(tmpfilename2) def test_unknown_kwargs_raises_error(self): - self.assertRaises(exception.UnknownArgumentError, + self.assertRaises(putils.UnknownArgumentError, utils.execute, '/usr/bin/env', 'true', this_is_not_a_valid_kwarg=True) def test_check_exit_code_boolean(self): utils.execute('/usr/bin/env', 'false', check_exit_code=False) - self.assertRaises(exception.ProcessExecutionError, + self.assertRaises(putils.ProcessExecutionError, utils.execute, '/usr/bin/env', 'false', check_exit_code=True) @@ -359,7 +359,7 @@ class GenericUtilsTestCase(test.TestCase): def test_read_file_as_root(self): def fake_execute(*args, **kwargs): if args[1] == 'bad': - raise exception.ProcessExecutionError + raise putils.ProcessExecutionError return 'fakecontents', None self.stubs.Set(utils, 'execute', fake_execute) diff --git a/cinder/utils.py b/cinder/utils.py index 84741bf9a..3a3ba2fe0 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -140,18 +140,7 @@ def execute(*cmd, **kwargs): """Convenience wrapper around oslo's execute() method.""" if 'run_as_root' in kwargs and not 'root_helper' in kwargs: kwargs['root_helper'] = get_root_helper() - try: - (stdout, stderr) = processutils.execute(*cmd, **kwargs) - except processutils.ProcessExecutionError as ex: - raise exception.ProcessExecutionError( - exit_code=ex.exit_code, - stderr=ex.stderr, - stdout=ex.stdout, - cmd=ex.cmd, - description=ex.description) - except processutils.UnknownArgumentError as ex: - raise exception.UnknownArgumentError(ex.message) - return (stdout, stderr) + return processutils.execute(*cmd, **kwargs) def check_ssh_injection(cmd_list): @@ -836,7 +825,7 @@ def read_file_as_root(file_path): try: out, _err = execute('cat', file_path, run_as_root=True) return out - except exception.ProcessExecutionError: + except processutils.ProcessExecutionError: raise exception.FileNotFound(file_path=file_path) diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index af21dbbf9..941e342a4 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -31,6 +31,7 @@ from cinder.image import image_utils from cinder.openstack.common import excutils from cinder.openstack.common import fileutils from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import utils from cinder.volume import rpcapi as volume_rpcapi from cinder.volume import utils as volume_utils @@ -134,7 +135,7 @@ class VolumeDriver(object): try: self._execute(*command, **kwargs) return True - except exception.ProcessExecutionError as ex: + except processutils.ProcessExecutionError as ex: tries = tries + 1 if tries >= self.configuration.num_shell_tries or\ @@ -814,7 +815,7 @@ class ISERDriver(ISCSIDriver): out, info = None, None try: out, info = self._execute(*cmd, run_as_root=True) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: LOG.error(_("Failed to access the device on the path " "%(path)s: %(error)s.") % {"path": path, "error": e.stderr}) @@ -834,7 +835,7 @@ class ISERDriver(ISCSIDriver): # code "inspired by" nova/virt/libvirt/volume.py try: self._run_iscsiadm(iser_properties, ()) - except exception.ProcessExecutionError as exc: + except processutils.ProcessExecutionError as exc: # iscsiadm returns 21 for "No records found" after version 2.0-871 if exc.exit_code in [21, 255]: self._run_iscsiadm(iser_properties, ('--op', 'new')) @@ -873,7 +874,7 @@ class ISERDriver(ISCSIDriver): try: self._run_iscsiadm(iser_properties, ("--login",), check_exit_code=[0, 255]) - except exception.ProcessExecutionError as err: + except processutils.ProcessExecutionError as err: if err.exit_code in [15]: self._iscsiadm_update(iser_properties, "node.startup", diff --git a/cinder/volume/drivers/gpfs.py b/cinder/volume/drivers/gpfs.py index b83973d20..9b156f0e5 100644 --- a/cinder/volume/drivers/gpfs.py +++ b/cinder/volume/drivers/gpfs.py @@ -29,6 +29,7 @@ from cinder import exception from cinder.image import image_utils from cinder.openstack.common import fileutils from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import units from cinder.volume import driver @@ -189,7 +190,7 @@ class GPFSDriver(driver.VolumeDriver): try: # check that configured directories are on GPFS self._is_gpfs_path(directory) - except exception.ProcessExecutionError: + except processutils.ProcessExecutionError: msg = (_('%s is not on GPFS. Perhaps GPFS not mounted.') % directory) LOG.error(msg) @@ -460,7 +461,7 @@ class GPFSDriver(driver.VolumeDriver): image_path = os.path.join(self.configuration.gpfs_images_dir, image_id) try: self._is_gpfs_path(image_path) - except exception.ProcessExecutionError: + except processutils.ProcessExecutionError: reason = 'image file not in GPFS' return False, reason, None @@ -561,7 +562,7 @@ class GPFSDriver(driver.VolumeDriver): cmd.append(path) try: self._execute(*cmd, run_as_root=True) - except exception.ProcessExecutionError as exc: + except processutils.ProcessExecutionError as exc: exception_message = (_("mkfs failed on volume %(vol)s, " "error message was: %(err)s") % {'vol': volume['name'], 'err': exc.stderr}) diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index 6e6ace625..2c0bdc23b 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -33,6 +33,7 @@ from cinder import exception from cinder.image import image_utils from cinder.openstack.common import fileutils from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import utils from cinder.volume import driver from cinder.volume import utils as volutils @@ -109,7 +110,7 @@ class LVMVolumeDriver(driver.VolumeDriver): if self.vg.get_volume(pool_name) is None: try: self.vg.create_thin_pool(pool_name) - except exception.ProcessExecutionError as exc: + except processutils.ProcessExecutionError as exc: exception_message = ("Failed to create thin pool, " "error message was: %s" % exc.stderr) @@ -481,7 +482,7 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): try: (out, err) = self._execute('readlink', old_name) - except exception.ProcessExecutionError: + except processutils.ProcessExecutionError: link_path = '/dev/%s/%s' % (self.configuration.volume_group, old_name) LOG.debug(_('Symbolic link %s not found') % link_path) diff --git a/cinder/volume/drivers/netapp/nfs.py b/cinder/volume/drivers/netapp/nfs.py index 05ce1796d..35c64f235 100644 --- a/cinder/volume/drivers/netapp/nfs.py +++ b/cinder/volume/drivers/netapp/nfs.py @@ -24,6 +24,7 @@ import time from cinder import exception from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder.volume.drivers.netapp.api import NaApiError from cinder.volume.drivers.netapp.api import NaElement from cinder.volume.drivers.netapp.api import NaServer @@ -136,7 +137,7 @@ class NetAppNFSDriver(nfs.NfsDriver): try: self._try_execute('ls', self._get_volume_path(nfs_mount, volume_name)) - except exception.ProcessExecutionError: + except processutils.ProcessExecutionError: # If the volume isn't present return True return False @@ -150,7 +151,7 @@ class NetAppNFSDriver(nfs.NfsDriver): try: self._execute(*command, **kwargs) return True - except exception.ProcessExecutionError: + except processutils.ProcessExecutionError: tries = tries + 1 if tries >= self.configuration.num_shell_tries: raise diff --git a/cinder/volume/drivers/nfs.py b/cinder/volume/drivers/nfs.py index 14f598ac0..1fd65a8a6 100644 --- a/cinder/volume/drivers/nfs.py +++ b/cinder/volume/drivers/nfs.py @@ -24,6 +24,7 @@ from oslo.config import cfg from cinder import exception from cinder.image import image_utils from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import units from cinder.volume import driver @@ -333,7 +334,7 @@ class RemoteFsDriver(driver.VolumeDriver): """ try: self._execute(*cmd, run_as_root=True) - except exception.ProcessExecutionError as exc: + except processutils.ProcessExecutionError as exc: if ensure and 'already mounted' in exc.stderr: LOG.warn(_("%s is already mounted"), share) else: diff --git a/cinder/volume/drivers/san/hp/hp_3par_common.py b/cinder/volume/drivers/san/hp/hp_3par_common.py index 15350a28c..3b944fb90 100644 --- a/cinder/volume/drivers/san/hp/hp_3par_common.py +++ b/cinder/volume/drivers/san/hp/hp_3par_common.py @@ -57,6 +57,7 @@ from cinder import context from cinder import exception from cinder.openstack.common import excutils from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import utils from cinder.volume import volume_types @@ -314,10 +315,10 @@ exit if exit_status != -1: LOG.debug(_('Result was %s') % exit_status) if check_exit_code and exit_status != 0: - raise exception.ProcessExecutionError(exit_code=exit_status, - stdout=stdout, - stderr=stderr, - cmd=cmd) + raise processutils.ProcessExecutionError(exit_code=exit_status, + stdout=stdout, + stderr=stderr, + cmd=cmd) channel.close() return (stdout, stderr) diff --git a/cinder/volume/drivers/san/hp_lefthand.py b/cinder/volume/drivers/san/hp_lefthand.py index c02dd7692..8e22662d9 100644 --- a/cinder/volume/drivers/san/hp_lefthand.py +++ b/cinder/volume/drivers/san/hp_lefthand.py @@ -21,6 +21,7 @@ from lxml import etree from cinder import exception from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder.volume.drivers.san.san import SanISCSIDriver @@ -228,7 +229,7 @@ class HpSanISCSIDriver(SanISCSIDriver): cliq_args['prompt'] = 'false' # Don't confirm try: volume_info = self._cliq_get_volume_info(volume['name']) - except exception.ProcessExecutionError: + except processutils.ProcessExecutionError: LOG.error("Volume did not exist. It will not be deleted") return self._cliq_run_xml("deleteVolume", cliq_args) diff --git a/cinder/volume/drivers/san/san.py b/cinder/volume/drivers/san/san.py index 59d3b596e..ce3c1fdb4 100644 --- a/cinder/volume/drivers/san/san.py +++ b/cinder/volume/drivers/san/san.py @@ -134,13 +134,13 @@ class SanDriver(driver.VolumeDriver): last_exception = e greenthread.sleep(random.randint(20, 500) / 100.0) try: - raise exception.ProcessExecutionError( + raise processutils.ProcessExecutionError( exit_code=last_exception.exit_code, stdout=last_exception.stdout, stderr=last_exception.stderr, cmd=last_exception.cmd) except AttributeError: - raise exception.ProcessExecutionError( + raise processutils.ProcessExecutionError( exit_code=-1, stdout="", stderr="Error running SSH command", diff --git a/cinder/volume/drivers/sheepdog.py b/cinder/volume/drivers/sheepdog.py index 92033c324..28b07ba45 100644 --- a/cinder/volume/drivers/sheepdog.py +++ b/cinder/volume/drivers/sheepdog.py @@ -27,6 +27,7 @@ from oslo.config import cfg from cinder import exception from cinder.image import image_utils from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder import units from cinder.volume import driver @@ -59,7 +60,7 @@ class SheepdogDriver(driver.VolumeDriver): raise exception.VolumeBackendAPIException( data=exception_message) - except exception.ProcessExecutionError: + except processutils.ProcessExecutionError: exception_message = _("Sheepdog is not working") raise exception.VolumeBackendAPIException(data=exception_message) @@ -173,7 +174,7 @@ class SheepdogDriver(driver.VolumeDriver): used = float(m.group(2)) stats['total_capacity_gb'] = total / (1024 ** 3) stats['free_capacity_gb'] = (total - used) / (1024 ** 3) - except exception.ProcessExecutionError: + except processutils.ProcessExecutionError: LOG.exception(_('error refreshing volume stats')) self._stats = stats diff --git a/cinder/volume/drivers/storwize_svc.py b/cinder/volume/drivers/storwize_svc.py index a6350796e..4e92eb2c7 100644 --- a/cinder/volume/drivers/storwize_svc.py +++ b/cinder/volume/drivers/storwize_svc.py @@ -51,6 +51,7 @@ from cinder import context from cinder import exception from cinder.openstack.common import excutils from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils from cinder.openstack.common import strutils from cinder import utils from cinder.volume.drivers.san import san @@ -211,7 +212,7 @@ class StorwizeSVCDriver(san.SanDriver): 'license_compression_capacity') and value != '0': self._compression_enabled = True break - except exception.ProcessExecutionError: + except processutils.ProcessExecutionError: LOG.exception(_('Failed to get license information.')) # Get the available I/O groups @@ -1055,7 +1056,7 @@ class StorwizeSVCDriver(san.SanDriver): def _call_prepare_fc_map(self, fc_map_id, source, target): try: out, err = self._run_ssh(['svctask', 'prestartfcmap', fc_map_id]) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: with excutils.save_and_reraise_exception(): LOG.error(_('_prepare_fc_map: Failed to prepare FlashCopy ' 'from %(source)s to %(target)s.\n' @@ -1113,7 +1114,7 @@ class StorwizeSVCDriver(san.SanDriver): def _start_fc_map(self, fc_map_id, source, target): try: out, err = self._run_ssh(['svctask', 'startfcmap', fc_map_id]) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: with excutils.save_and_reraise_exception(): LOG.error(_('_start_fc_map: Failed to start FlashCopy ' 'from %(source)s to %(target)s.\n' @@ -1527,7 +1528,7 @@ class StorwizeSVCDriver(san.SanDriver): try: out, err = self._run_ssh(ssh_cmd) - except exception.ProcessExecutionError as e: + except processutils.ProcessExecutionError as e: # Didn't get details from the storage, return None LOG.error(_('CLI Exception output:\n command: %(cmd)s\n ' 'stdout: %(out)s\n stderr: %(err)s') % diff --git a/cinder/volume/flows/create_volume.py b/cinder/volume/flows/create_volume.py index 22ebb3325..7bafa569b 100644 --- a/cinder/volume/flows/create_volume.py +++ b/cinder/volume/flows/create_volume.py @@ -34,6 +34,7 @@ from cinder import utils from cinder.openstack.common import excutils from cinder.openstack.common import log as logging from cinder.openstack.common.notifier import api as notifier +from cinder.openstack.common import processutils from cinder.openstack.common import timeutils from cinder.volume.flows import base from cinder.volume import utils as volume_utils @@ -1299,7 +1300,7 @@ class CreateVolumeFromSpecTask(base.CinderTask): 'image_location': image_location}) try: copy_image_to_volume(context, volume_ref, image_service, image_id) - except exception.ProcessExecutionError as ex: + except processutils.ProcessExecutionError as ex: LOG.error(_("Failed to copy image %(image_id)s to volume: " "%(volume_id)s, error: %(error)s") % {'volume_id': volume_id, diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index 41a2e19ec..97b94f28e 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -27,6 +27,7 @@ from cinder.brick.local_dev import lvm as brick_lvm from cinder import exception from cinder.openstack.common import log as logging from cinder.openstack.common.notifier import api as notifier_api +from cinder.openstack.common import processutils from cinder.openstack.common import strutils from cinder.openstack.common import timeutils from cinder import units @@ -177,7 +178,7 @@ def copy_volume(srcstr, deststr, size_in_m, sync=False, try: execute('dd', 'count=0', 'if=%s' % srcstr, 'of=%s' % deststr, *extra_flags, run_as_root=True) - except exception.ProcessExecutionError: + except processutils.ProcessExecutionError: extra_flags = [] # If the volume is being unprovisioned then