From d1fa401469b382fdec2af3efc1cb243d34977609 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Mon, 19 Aug 2013 12:03:35 +0800 Subject: [PATCH] Sync execute() related exceptions with oslo Cinder has its own ProcessExecutionError exception defined which already exists in processutils.py. This was done to have minimal editing when applying processutils.execute() to Cinder. As a result, new instances are being created for each exception raised during cli processing using execute() As for the first step to remove the redundant excptions, this patch syncs ProcessExecutionError and UnknownArgumentError with that in processutils to ease the transition. Change-Id: I88d9b86a0486f5d91fdcb664c99a9a2cd1392460 --- cinder/backup/drivers/ceph.py | 26 ++++++++++++++------------ cinder/exception.py | 30 +++++++----------------------- cinder/tests/test_utils.py | 2 +- cinder/utils.py | 2 +- 4 files changed, 23 insertions(+), 37 deletions(-) diff --git a/cinder/backup/drivers/ceph.py b/cinder/backup/drivers/ceph.py index 8d1464ce0..f63eb35a6 100644 --- a/cinder/backup/drivers/ceph.py +++ b/cinder/backup/drivers/ceph.py @@ -373,25 +373,27 @@ class CephBackupDriver(BackupDriver): src_ceph_args = self._ceph_args(src_user, src_conf, pool=src_pool) dest_ceph_args = self._ceph_args(dest_user, dest_conf, pool=dest_pool) + cmd = ['rbd', 'export-diff'] + src_ceph_args + if from_snap is not None: + cmd.extend(['--from-snap', from_snap]) + if src_snap: + path = self._utf8("%s/%s@%s" % (src_pool, src_name, src_snap)) + else: + path = self._utf8("%s/%s" % (src_pool, src_name)) + cmd.extend([path, '-']) try: - cmd = ['rbd', 'export-diff'] + src_ceph_args - if from_snap is not None: - cmd.extend(['--from-snap', from_snap]) - if src_snap: - path = self._utf8("%s/%s@%s" % (src_pool, src_name, src_snap)) - else: - path = self._utf8("%s/%s" % (src_pool, src_name)) - cmd.extend([path, '-']) out, err = self._execute(*cmd) - except (exception.ProcessExecutionError, exception.Error) as exc: + except (exception.ProcessExecutionError, + exception.UnknownArgumentError) as exc: LOG.info(_("rbd export-diff failed - %s") % (str(exc))) raise exception.BackupRBDOperationFailed("rbd export-diff failed") + cmd = ['rbd', 'import-diff'] + dest_ceph_args + cmd.extend(['-', self._utf8("%s/%s" % (dest_pool, dest_name))]) try: - cmd = ['rbd', 'import-diff'] + dest_ceph_args - cmd.extend(['-', self._utf8("%s/%s" % (dest_pool, dest_name))]) out, err = self._execute(*cmd, process_input=out) - except (exception.ProcessExecutionError, exception.Error) as exc: + except (exception.ProcessExecutionError, + exception.UnknownArgumentError) as exc: LOG.info(_("rbd import-diff failed - %s") % (str(exc))) raise exception.BackupRBDOperationFailed("rbd import-diff failed") diff --git a/cinder/exception.py b/cinder/exception.py index 1d6141345..c1ea7382c 100644 --- a/cinder/exception.py +++ b/cinder/exception.py @@ -30,6 +30,7 @@ from oslo.config import cfg import webob.exc from cinder.openstack.common import log as logging +from cinder.openstack.common import processutils LOG = logging.getLogger(__name__) @@ -52,29 +53,12 @@ class ConvertedException(webob.exc.WSGIHTTPException): super(ConvertedException, self).__init__() -class ProcessExecutionError(IOError): - def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None, - description=None): - self.exit_code = exit_code - self.stderr = stderr - self.stdout = stdout - self.cmd = cmd - self.description = description - - if description is None: - description = _('Unexpected error while running command.') - if exit_code is None: - exit_code = '-' - message = _('%(description)s\nCommand: %(cmd)s\n' - 'Exit code: %(exit_code)s\nStdout: %(stdout)r\n' - 'Stderr: %(stderr)r') % { - 'description': description, - 'cmd': cmd, - 'exit_code': exit_code, - 'stdout': stdout, - 'stderr': stderr, - } - IOError.__init__(self, message) +class ProcessExecutionError(processutils.ProcessExecutionError): + pass + + +class UnknownArgumentError(processutils.UnknownArgumentError): + pass class Error(Exception): diff --git a/cinder/tests/test_utils.py b/cinder/tests/test_utils.py index 0a50d3f5e..7a6c4b4be 100644 --- a/cinder/tests/test_utils.py +++ b/cinder/tests/test_utils.py @@ -88,7 +88,7 @@ exit 1 os.unlink(tmpfilename2) def test_unknown_kwargs_raises_error(self): - self.assertRaises(exception.Error, + self.assertRaises(exception.UnknownArgumentError, utils.execute, '/usr/bin/env', 'true', this_is_not_a_valid_kwarg=True) diff --git a/cinder/utils.py b/cinder/utils.py index 6c4af373b..84741bf9a 100644 --- a/cinder/utils.py +++ b/cinder/utils.py @@ -150,7 +150,7 @@ def execute(*cmd, **kwargs): cmd=ex.cmd, description=ex.description) except processutils.UnknownArgumentError as ex: - raise exception.Error(ex.message) + raise exception.UnknownArgumentError(ex.message) return (stdout, stderr) -- 2.45.2