From a283893c16f2eeea1390f6656cbd633ba4f8b616 Mon Sep 17 00:00:00 2001 From: Chris Behrens Date: Thu, 31 May 2012 18:09:23 +0000 Subject: [PATCH] Don't deepcopy RpcContext 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 --- nova/rpc/amqp.py | 6 ++++++ nova/rpc/common.py | 5 ++++- nova/rpc/impl_fake.py | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/nova/rpc/amqp.py b/nova/rpc/amqp.py index 8df16ff9..8e5d685d 100644 --- a/nova/rpc/amqp.py +++ b/nova/rpc/amqp.py @@ -175,6 +175,12 @@ class RpcContext(rpc_common.CommonRpcContext): 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: diff --git a/nova/rpc/common.py b/nova/rpc/common.py index c5f88f90..0b927a0e 100644 --- a/nova/rpc/common.py +++ b/nova/rpc/common.py @@ -287,6 +287,9 @@ class CommonRpcContext(object): 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 @@ -299,7 +302,7 @@ class CommonRpcContext(object): # 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', []) diff --git a/nova/rpc/impl_fake.py b/nova/rpc/impl_fake.py index 54bd2497..24ef0e7c 100644 --- a/nova/rpc/impl_fake.py +++ b/nova/rpc/impl_fake.py @@ -34,6 +34,13 @@ class RpcContext(rpc_common.CommonRpcContext): 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