summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-05-30 20:11:41 +0000
committerGerrit Code Review <review@openstack.org>2012-05-30 20:11:41 +0000
commit2a726d06e2ec41758e4460a2138e1af51509cc14 (patch)
treee1ff3ad74fb9b4f5c71e228494fb5edf9f526801
parentbb93b4b209491602f6c5f7fecff9b1192a3ec968 (diff)
parenta427d04901b57789b4127c8b8c79b6b7141d8e3a (diff)
downloadnova-2a726d06e2ec41758e4460a2138e1af51509cc14.tar.gz
nova-2a726d06e2ec41758e4460a2138e1af51509cc14.tar.xz
nova-2a726d06e2ec41758e4460a2138e1af51509cc14.zip
Merge changes I17ca4b69,I9e6ec0d2
* changes: Remove nova.log usage from nova.rpc. Remove nova.context dependency from nova.rpc
-rw-r--r--nova/rpc/amqp.py9
-rw-r--r--nova/rpc/common.py46
-rw-r--r--nova/rpc/impl_fake.py7
-rw-r--r--nova/rpc/impl_qpid.py2
4 files changed, 53 insertions, 11 deletions
diff --git a/nova/rpc/amqp.py b/nova/rpc/amqp.py
index 93f18fb1b..8df16ff9d 100644
--- a/nova/rpc/amqp.py
+++ b/nova/rpc/amqp.py
@@ -26,6 +26,7 @@ AMQP, but is deprecated and predates this code.
"""
import inspect
+import logging
import sys
import uuid
@@ -33,8 +34,6 @@ from eventlet import greenpool
from eventlet import pools
from eventlet import semaphore
-from nova import context
-from nova import log as logging
from nova.openstack.common import excutils
from nova.openstack.common import local
import nova.rpc.common as rpc_common
@@ -169,12 +168,12 @@ def msg_reply(conf, msg_id, connection_pool, reply=None, failure=None,
conn.direct_send(msg_id, msg)
-class RpcContext(context.RequestContext):
+class RpcContext(rpc_common.CommonRpcContext):
"""Context that supports replying to a rpc.call"""
- def __init__(self, *args, **kwargs):
+ def __init__(self, **kwargs):
self.msg_id = kwargs.pop('msg_id', None)
self.conf = kwargs.pop('conf')
- super(RpcContext, self).__init__(*args, **kwargs)
+ super(RpcContext, self).__init__(**kwargs)
def reply(self, reply=None, failure=None, ending=False,
connection_pool=None):
diff --git a/nova/rpc/common.py b/nova/rpc/common.py
index 120b41c14..c5f88f90b 100644
--- a/nova/rpc/common.py
+++ b/nova/rpc/common.py
@@ -18,13 +18,14 @@
# under the License.
import copy
+import logging
import sys
import traceback
-from nova import log as logging
from nova.openstack.common import cfg
from nova.openstack.common import importutils
from nova.openstack.common import jsonutils
+from nova.openstack.common import local
LOG = logging.getLogger(__name__)
@@ -267,3 +268,46 @@ def deserialize_remote_exception(conf, data):
# first exception argument.
failure.args = (message,) + failure.args[1:]
return failure
+
+
+class CommonRpcContext(object):
+ def __init__(self, **kwargs):
+ self.values = kwargs
+
+ def __getattr__(self, key):
+ try:
+ return self.values[key]
+ except KeyError:
+ raise AttributeError(key)
+
+ def to_dict(self):
+ return copy.deepcopy(self.values)
+
+ @classmethod
+ def from_dict(cls, values):
+ return cls(**values)
+
+ def update_store(self):
+ local.store.context = self
+
+ def elevated(self, read_deleted=None, overwrite=False):
+ """Return a version of this context with admin flag set."""
+ # TODO(russellb) This method is a bit of a nova-ism. It makes
+ # some assumptions about the data in the request context sent
+ # across rpc, while the rest of this class does not. We could get
+ # rid of this if we changed the nova code that uses this to
+ # convert the RpcContext back to its native RequestContext doing
+ # something like nova.context.RequestContext.from_dict(ctxt.to_dict())
+
+ context = copy.deepcopy(self)
+ context.values['is_admin'] = True
+
+ context.values.setdefault('roles', [])
+
+ if 'admin' not in context.values['roles']:
+ context.values['roles'].append('admin')
+
+ if read_deleted is not None:
+ context.values['read_deleted'] = read_deleted
+
+ return context
diff --git a/nova/rpc/impl_fake.py b/nova/rpc/impl_fake.py
index 70a8ca5f7..a6af6247b 100644
--- a/nova/rpc/impl_fake.py
+++ b/nova/rpc/impl_fake.py
@@ -23,15 +23,14 @@ import time
import eventlet
-from nova import context
from nova.rpc import common as rpc_common
CONSUMERS = {}
-class RpcContext(context.RequestContext):
- def __init__(self, *args, **kwargs):
- super(RpcContext, self).__init__(*args, **kwargs)
+class RpcContext(rpc_common.CommonRpcContext):
+ def __init__(self, **kwargs):
+ super(RpcContext, self).__init__(**kwargs)
self._response = []
self._done = False
diff --git a/nova/rpc/impl_qpid.py b/nova/rpc/impl_qpid.py
index dad47defc..77d39407e 100644
--- a/nova/rpc/impl_qpid.py
+++ b/nova/rpc/impl_qpid.py
@@ -18,6 +18,7 @@
import functools
import itertools
import json
+import logging
import time
import uuid
@@ -26,7 +27,6 @@ import greenlet
import qpid.messaging
import qpid.messaging.exceptions
-from nova import log as logging
from nova.openstack.common import cfg
from nova.rpc import amqp as rpc_amqp
from nova.rpc import common as rpc_common