Pop extra keys from context in from_dict()
RequestContext.to_dict() adds user/tenant keys, but from_dict() spews this warning a "Arguments dropped when creating context" if you pass a dict which contains user/tenant keys. Seems to make perfect sense that from_dict() would remove these extra keys. A test case ensures this won't happen for new arguments. This is import for oslo.messaging because we deserialize request context dicts into nova's RequestContext using from_dict(). blueprint: oslo-messaging Change-Id: I0938f3c7c581383cbebc3a973d64454250f6ab8e
This commit is contained in:
parent
4a661dd961
commit
5e573aa611
|
@ -139,6 +139,8 @@ class RequestContext(object):
|
|||
|
||||
@classmethod
|
||||
def from_dict(cls, values):
|
||||
values.pop('user', None)
|
||||
values.pop('tenant', None)
|
||||
return cls(**values)
|
||||
|
||||
def elevated(self, read_deleted=None, overwrite=False):
|
||||
|
|
|
@ -101,3 +101,21 @@ class ContextTestCase(test.TestCase):
|
|||
ctxt = context.RequestContext('111', '222',
|
||||
service_catalog=service_catalog)
|
||||
self.assertEquals(ctxt.service_catalog, volume_catalog)
|
||||
|
||||
def test_to_dict_from_dict_no_log(self):
|
||||
warns = []
|
||||
|
||||
def stub_warn(msg, *a, **kw):
|
||||
if (a and len(a) == 1 and isinstance(a[0], dict) and a[0]):
|
||||
a = a[0]
|
||||
warns.append(str(msg) % a)
|
||||
|
||||
self.stubs.Set(context.LOG, 'warn', stub_warn)
|
||||
|
||||
ctxt = context.RequestContext('111',
|
||||
'222',
|
||||
roles=['admin', 'weasel'])
|
||||
|
||||
ctxt = context.RequestContext.from_dict(ctxt.to_dict())
|
||||
|
||||
self.assertEqual(len(warns), 0, warns)
|
||||
|
|
Loading…
Reference in New Issue