:param kwargs: Extra arguments that might be present, but we ignore
because they possibly came in from older rpc messages.
"""
- if kwargs:
- LOG.warn(_('Arguments dropped when creating '
- 'context: %s'), kwargs)
-
super(ContextBase, self).__init__(user=user_id, tenant=tenant_id,
is_admin=is_admin,
request_id=request_id)
if overwrite or not hasattr(local.store, 'context'):
local.store.context = self
+ # Log only once the context has been configured to prevent
+ # format errors.
+ if kwargs:
+ LOG.warn(_('Arguments dropped when creating '
+ 'context: %s'), kwargs)
+
@property
def project_id(self):
return self.tenant
'tenant': self.tenant,
'user': self.user,
'tenant_name': self.tenant_name,
+ 'project_name': self.tenant_name,
'user_name': self.user_name,
}
self.assertIsNone(ctx.user_name)
self.assertIsNone(ctx.tenant_name)
+ def test_neutron_context_create_logs_unknown_kwargs(self):
+ with mock.patch.object(context.LOG, 'warn') as mock_warn:
+ context.Context('user_id', 'tenant_id', foo='bar')
+ self.assertEqual(mock_warn.call_count, 1)
+
def test_neutron_context_create_with_name(self):
ctx = context.Context('user_id', 'tenant_id',
tenant_name='tenant_name', user_name='user_name')
self.assertEqual('tenant_id', ctx_dict['tenant'])
self.assertIsNone(ctx_dict['user_name'])
self.assertIsNone(ctx_dict['tenant_name'])
+ self.assertIsNone(ctx_dict['project_name'])
def test_neutron_context_to_dict_with_name(self):
ctx = context.Context('user_id', 'tenant_id',
ctx_dict = ctx.to_dict()
self.assertEqual('user_name', ctx_dict['user_name'])
self.assertEqual('tenant_name', ctx_dict['tenant_name'])
+ self.assertEqual('tenant_name', ctx_dict['project_name'])
def test_neutron_context_admin_to_dict(self):
self.db_api_session.return_value = 'fakesession'