Skip to content

Commit

Permalink
Don't deepcopy RpcContext
Browse files Browse the repository at this point in the history
Instead of deepcopying the RpcContext, which seems to not work
sometimes, we'll explicitly create a new instance of the class and
deepcopy the required values.

Fixes bug 1007043

Change-Id: I6578c4c82046acf149724a1c5985fa6b46857a7c
  • Loading branch information
comstud committed May 31, 2012
1 parent 9e80073 commit 5fcdaf8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions nova/rpc/amqp.py
Expand Up @@ -175,6 +175,12 @@ def __init__(self, **kwargs):
self.conf = kwargs.pop('conf')
super(RpcContext, self).__init__(**kwargs)

def deepcopy(self):
values = self.to_dict()
values['conf'] = self.conf
values['msg_id'] = self.msg_id
return self.__class__(**values)

def reply(self, reply=None, failure=None, ending=False,
connection_pool=None):
if self.msg_id:
Expand Down
5 changes: 4 additions & 1 deletion nova/rpc/common.py
Expand Up @@ -287,6 +287,9 @@ def to_dict(self):
def from_dict(cls, values):
return cls(**values)

def deepcopy(self):
return self.from_dict(self.to_dict())

def update_store(self):
local.store.context = self

Expand All @@ -299,7 +302,7 @@ def elevated(self, read_deleted=None, overwrite=False):
# convert the RpcContext back to its native RequestContext doing
# something like nova.context.RequestContext.from_dict(ctxt.to_dict())

context = copy.deepcopy(self)
context = self.deepcopy()
context.values['is_admin'] = True

context.values.setdefault('roles', [])
Expand Down
7 changes: 7 additions & 0 deletions nova/rpc/impl_fake.py
Expand Up @@ -34,6 +34,13 @@ def __init__(self, **kwargs):
self._response = []
self._done = False

def deepcopy(self):
values = self.to_dict()
new_inst = self.__class__(**values)
new_inst._response = self._response
new_inst._done = self._done
return new_inst

def reply(self, reply=None, failure=None, ending=False):
if ending:
self._done = True
Expand Down

0 comments on commit 5fcdaf8

Please sign in to comment.