Fix format errors seen in rpc logging
The previous commit for this bug didn't include the 'project_name' key in the context dict. The missing key was causing the amqp module to generate log formatting exceptions instead of normal log output. Separately, the context module itself was generating logging exceptions in the quantum service when logging was attempted before the context was fully initialized Change-Id: I0f4c6f5a6804442932c9b2bd409a258cfc2419ff Closes-Bug: #1254530 Related-Bug: #1239923
This commit is contained in:
parent
ef8e172b00
commit
46b1d13f25
@ -54,10 +54,6 @@ class ContextBase(common_context.RequestContext):
|
||||
: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)
|
||||
@ -81,6 +77,12 @@ class ContextBase(common_context.RequestContext):
|
||||
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
|
||||
@ -128,6 +130,7 @@ class ContextBase(common_context.RequestContext):
|
||||
'tenant': self.tenant,
|
||||
'user': self.user,
|
||||
'tenant_name': self.tenant_name,
|
||||
'project_name': self.tenant_name,
|
||||
'user_name': self.user_name,
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,11 @@ class TestNeutronContext(base.BaseTestCase):
|
||||
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')
|
||||
@ -67,6 +72,7 @@ class TestNeutronContext(base.BaseTestCase):
|
||||
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',
|
||||
@ -74,6 +80,7 @@ class TestNeutronContext(base.BaseTestCase):
|
||||
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'
|
||||
|
Loading…
Reference in New Issue
Block a user