]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Sync execute() related exceptions with oslo
authorZhongyue Luo <zhongyue.nah@intel.com>
Mon, 19 Aug 2013 04:03:35 +0000 (12:03 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Fri, 23 Aug 2013 19:12:54 +0000 (04:12 +0900)
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
cinder/exception.py
cinder/tests/test_utils.py
cinder/utils.py

index 8d1464ce0a92b9dff2dc9f4eb18cfef5fa2df85c..f63eb35a6149e0d1231b0687e214c40e74cda709 100644 (file)
@@ -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")
 
index 1d6141345bffffe92b7dc5ee38a2542efec417c6..c1ea7382cb917bffa4aab9df5c419beea510e9cd 100644 (file)
@@ -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):
index 0a50d3f5e93a1c10860f61ca2a0885322c24c5e1..7a6c4b4bec031537fa8c1079ea96e1c49118ad55 100644 (file)
@@ -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)
index 6c4af373beeaa49234b1b05602e9302793ba8fbb..84741bf9acafef83798d2dd77d67e022b0ef207e 100644 (file)
@@ -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)