From 9e4242c3865da976928ecd43ef82030ac8bfc8cf Mon Sep 17 00:00:00 2001
From: Russell Bryant <rbryant@redhat.com>
Date: Tue, 15 May 2012 14:43:18 -0400
Subject: [PATCH] Stop using cinder.exception from cinder.rpc.

This patch is a part of continuing to remove dependencies from cinder.rpc
on the rest of cinder.  One RPC related exception was defined in
cinder.exception, so that was moved to cinder.rpc.common where the rest of
them live.  These exceptions were changed to no longer use CinderException
as their base.  Instead, there is a new RPCException base.

One other change that should be reviewed closely is the removal of using
cinder.exception.wrap_exception() in cinder.rpc.amqp.  As far as I can tell,
this didn't actually do anything since nothing was being passed in to
wrap_exception().

Change-Id: I36ff7c05ab0467ad8506b56d561c532eadf8dff8
Reviewed-on: https://review.openstack.org/9899
Reviewed-by: Vish Ishaya <vishvananda@gmail.com>
Approved: John Griffith <john.griffith@solidfire.com>
Tested-by: Jenkins
---
 cinder/exception.py  |  4 ----
 cinder/rpc/amqp.py   |  4 +---
 cinder/rpc/common.py | 31 ++++++++++++++++++++++++++++---
 3 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/cinder/exception.py b/cinder/exception.py
index e92da9963..eacf5f4f0 100644
--- a/cinder/exception.py
+++ b/cinder/exception.py
@@ -270,10 +270,6 @@ class InvalidCidr(Invalid):
     message = _("Invalid cidr %(cidr)s.")
 
 
-class InvalidRPCConnectionReuse(Invalid):
-    message = _("Invalid reuse of an RPC connection.")
-
-
 class InvalidUnicodeParameter(Invalid):
     message = _("Invalid Parameter: "
                 "Unicode is not supported by the current database.")
diff --git a/cinder/rpc/amqp.py b/cinder/rpc/amqp.py
index b559ca78d..1c1341e43 100644
--- a/cinder/rpc/amqp.py
+++ b/cinder/rpc/amqp.py
@@ -34,7 +34,6 @@ from eventlet import pools
 from eventlet import semaphore
 
 from cinder import context
-from cinder import exception
 from cinder import log as logging
 from cinder.openstack.common import local
 import cinder.rpc.common as rpc_common
@@ -140,7 +139,7 @@ class ConnectionContext(rpc_common.Connection):
         if self.connection:
             return getattr(self.connection, key)
         else:
-            raise exception.InvalidRPCConnectionReuse()
+            raise rpc_common.InvalidRPCConnectionReuse()
 
 
 def msg_reply(conf, msg_id, connection_pool, reply=None, failure=None,
@@ -249,7 +248,6 @@ class ProxyCallback(object):
             return
         self.pool.spawn_n(self._process_data, ctxt, method, args)
 
-    @exception.wrap_exception()
     def _process_data(self, ctxt, method, args):
         """Thread that magically looks for a method on the proxy
         object and calls it.
diff --git a/cinder/rpc/common.py b/cinder/rpc/common.py
index 4dfaa3f76..501f69a8a 100644
--- a/cinder/rpc/common.py
+++ b/cinder/rpc/common.py
@@ -21,7 +21,6 @@ import copy
 import sys
 import traceback
 
-from cinder import exception
 from cinder import log as logging
 from cinder.openstack.common import cfg
 from cinder.openstack.common import importutils
@@ -31,7 +30,29 @@ from cinder import utils
 LOG = logging.getLogger(__name__)
 
 
-class RemoteError(exception.CinderException):
+class RPCException(Exception):
+    message = _("An unknown RPC related exception occurred.")
+
+    def __init__(self, message=None, **kwargs):
+        self.kwargs = kwargs
+
+        if not message:
+            try:
+                message = self.message % kwargs
+
+            except Exception as e:
+                # kwargs doesn't match a variable in the message
+                # log the issue and the kwargs
+                LOG.exception(_('Exception in string format operation'))
+                for name, value in kwargs.iteritems():
+                    LOG.error("%s: %s" % (name, value))
+                # at least get the core message out if something happened
+                message = self.message
+
+        super(RPCException, self).__init__(message)
+
+
+class RemoteError(RPCException):
     """Signifies that a remote class has raised an exception.
 
     Contains a string representation of the type of the original exception,
@@ -51,7 +72,7 @@ class RemoteError(exception.CinderException):
                                           traceback=traceback)
 
 
-class Timeout(exception.CinderException):
+class Timeout(RPCException):
     """Signifies that a timeout has occurred.
 
     This exception is raised if the rpc_response_timeout is reached while
@@ -60,6 +81,10 @@ class Timeout(exception.CinderException):
     message = _("Timeout while waiting on RPC response.")
 
 
+class InvalidRPCConnectionReuse(RPCException):
+    message = _("Invalid reuse of an RPC connection.")
+
+
 class Connection(object):
     """A connection, returned by rpc.create_connection().
 
-- 
2.45.2