diff options
author | Vishvananda Ishaya <vishvananda@gmail.com> | 2012-01-09 16:07:43 -0800 |
---|---|---|
committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2012-01-09 16:35:25 -0800 |
commit | 3d0311df9e3fccf96bde34e72f8011843941ac98 (patch) | |
tree | 9fe3e558f72b09344680405c0e4551979ad9215d /nova/context.py | |
parent | 51c0d545253b9f5618d1923aea3f7061da6cd60b (diff) | |
download | nova-3d0311df9e3fccf96bde34e72f8011843941ac98.tar.gz nova-3d0311df9e3fccf96bde34e72f8011843941ac98.tar.xz nova-3d0311df9e3fccf96bde34e72f8011843941ac98.zip |
Don't overwrite local context on elevated
* Adds an 'overwrite' parameter to context.__init__
* Overwrite is set to false for elevated and get_admin_context
* Fixes bug 899302
Change-Id: Ic9464e5813d6db38c48239c7ea8f15aa1bff5562
Diffstat (limited to 'nova/context.py')
-rw-r--r-- | nova/context.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/nova/context.py b/nova/context.py index cd07ca629..79ad0934d 100644 --- a/nova/context.py +++ b/nova/context.py @@ -35,11 +35,15 @@ class RequestContext(object): def __init__(self, user_id, project_id, is_admin=None, read_deleted="no", roles=None, remote_address=None, timestamp=None, - request_id=None, auth_token=None, strategy='noauth'): + request_id=None, auth_token=None, strategy='noauth', + overwrite=True): """ :param read_deleted: 'no' indicates deleted records are hidden, 'yes' indicates deleted records are visible, 'only' indicates that *only* deleted records are visible. + + :param overwrite: Set to False to ensure that the greenthread local + copy of the index is not overwritten. """ self.user_id = user_id self.project_id = project_id @@ -59,7 +63,8 @@ class RequestContext(object): self.request_id = request_id self.auth_token = auth_token self.strategy = strategy - local.store.context = self + if overwrite or not hasattr(local.store, 'context'): + local.store.context = self def to_dict(self): return {'user_id': self.user_id, @@ -77,7 +82,7 @@ class RequestContext(object): def from_dict(cls, values): return cls(**values) - def elevated(self, read_deleted=None): + def elevated(self, read_deleted=None, overwrite=False): """Return a version of this context with admin flag set.""" context = copy.copy(self) context.is_admin = True @@ -92,4 +97,5 @@ def get_admin_context(read_deleted="no"): return RequestContext(user_id=None, project_id=None, is_admin=True, - read_deleted=read_deleted) + read_deleted=read_deleted, + overwrite=False) |