Skip to content

Commit

Permalink
Add kwargs to RequestContext __init__
Browse files Browse the repository at this point in the history
Fixes bug 949726

This allows processing of rpc messages that contain older versions of
RequestContext to not raise an exception.

Change-Id: I4891a44280fcb8accf0cef1c00c1123029abcc96
  • Loading branch information
comstud committed Mar 8, 2012
1 parent 10c568a commit eba95d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion nova/context.py
Expand Up @@ -22,9 +22,13 @@
import copy

from nova import local
from nova import log as logging
from nova import utils


LOG = logging.getLogger(__name__)


def generate_request_id():
return 'req-' + str(utils.gen_uuid())

Expand All @@ -38,18 +42,24 @@ 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, overwrite=True):
request_id=None, auth_token=None, overwrite=True, **kwargs):
"""
: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.
:param kwargs: Extra arguments that might be present, but we ignore
because they possibly came in from older rpc messages.
"""
if read_deleted not in ('no', 'yes', 'only'):
raise ValueError(_("read_deleted can only be one of 'no', "
"'yes' or 'only', not %r") % read_deleted)
if kwargs:
LOG.warn(_('Arguments dropped when creating context: %s') %
str(kwargs))

self.user_id = user_id
self.project_id = project_id
Expand Down
14 changes: 14 additions & 0 deletions nova/tests/test_context.py
Expand Up @@ -44,3 +44,17 @@ def test_request_context_read_deleted_invalid(self):
'111',
'222',
read_deleted=True)

def test_extra_args_to_context_get_logged(self):
info = {}

def fake_warn(log_msg):
info['log_msg'] = log_msg

self.stubs.Set(context.LOG, 'warn', fake_warn)

c = context.RequestContext('user', 'project',
extra_arg1='meow', extra_arg2='wuff')
self.assertTrue(c)
self.assertIn("'extra_arg1': 'meow'", info['log_msg'])
self.assertIn("'extra_arg2': 'wuff'", info['log_msg'])

0 comments on commit eba95d1

Please sign in to comment.