Modify magnum api context to use user_name and project_name

Problem description:
If DevStack is used to instantiate the magnum plugin, and the
devstack localrc/local.conf has the default values for:
   LOG_COLOR (default value = True)
   SYSLOG (default value = False)
then upon startup (i.e. running DevStack's stack.sh), the magnum devstack
lib calls the DevStack common setup_colorized_logging function, but
without passing the optional 'project_var' and 'user_var' arguments to
this function. As a result, the setup_colorized_logging
function uses its default values of "user_name" and "project_name"
when it defines the logging_context_format_string (which in turn gets
configured in /etc/magnum/magnum.conf). The problem is that "user_name"
and "project_name" are not defined in the API context used by Magnum,
so that whenever the magnum plugin does a logging call, a KeyError
exception for the non-existant key "user_name" is generated.

Fix description:
The fix is to modify the Magnum context to use "user_name" and
"project_name" attributes to be consistent with the default context
format string set up by DevStack.

Change-Id: Ia0c34899609735ff9d8b4597101e004e2684657e
Closes-Bug: #1464376
This commit is contained in:
Dane LeBlanc 2015-06-11 16:01:22 -04:00
parent 81487bab3e
commit 617b772e55
4 changed files with 20 additions and 17 deletions

View File

@ -151,7 +151,7 @@ function create_magnum_conf {
setup_colorized_logging $MAGNUM_CONF DEFAULT
else
# Show user_name and project_name instead of user_id and project_id
iniset $MAGNUM_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(levelname)s %(name)s [%(request_id)s %(user)s %(project)s] %(instance)s%(message)s"
iniset $MAGNUM_CONF DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s] %(instance)s%(message)s"
fi
# Register SSL certificates if provided

View File

@ -66,9 +66,9 @@ class ContextHook(hooks.PecanHook):
auth_token=auth_token,
auth_url=auth_url,
auth_token_info=auth_token_info,
user=user,
user_name=user,
user_id=user_id,
project=project,
project_name=project,
project_id=project_id,
domain_id=domain_id,
domain_name=domain_name)

View File

@ -17,10 +17,11 @@ class RequestContext(context.RequestContext):
"""Extends security contexts from the OpenStack common library."""
def __init__(self, auth_token=None, auth_url=None, domain_id=None,
domain_name=None, user=None, user_id=None, project=None,
project_id=None, is_admin=False, is_public_api=False,
read_only=False, show_deleted=False, request_id=None,
trust_id=None, auth_token_info=None, **kwargs):
domain_name=None, user_name=None, user_id=None,
project_name=None, project_id=None, is_admin=False,
is_public_api=False, read_only=False, show_deleted=False,
request_id=None, trust_id=None, auth_token_info=None,
**kwargs):
"""Stores several additional request parameters:
:param domain_id: The ID of the domain.
@ -30,8 +31,9 @@ class RequestContext(context.RequestContext):
"""
self.is_public_api = is_public_api
self.user_name = user_name
self.user_id = user_id
self.project = project
self.project_name = project_name
self.project_id = project_id
self.domain_id = domain_id
self.domain_name = domain_name
@ -40,7 +42,8 @@ class RequestContext(context.RequestContext):
self.trust_id = trust_id
super(RequestContext, self).__init__(auth_token=auth_token,
user=user, tenant=project,
user=user_name,
tenant=project_name,
is_admin=is_admin,
read_only=read_only,
show_deleted=show_deleted,
@ -52,9 +55,9 @@ class RequestContext(context.RequestContext):
'auth_url': self.auth_url,
'domain_id': self.domain_id,
'domain_name': self.domain_name,
'user': self.user,
'user_name': self.user_name,
'user_id': self.user_id,
'project': self.project,
'project_name': self.project_name,
'project_id': self.project_id,
'is_admin': self.is_admin,
'is_public_api': self.is_public_api,

View File

@ -23,9 +23,9 @@ class ContextTestCase(base.TestCase):
auth_url='auth_url1',
domain_id='domain_id1',
domain_name='domain_name1',
user='user1',
user_name='user1',
user_id='user-id1',
project='tenant1',
project_name='tenant1',
project_id='tenant-id1',
is_admin=True,
is_public_api=True,
@ -42,9 +42,9 @@ class ContextTestCase(base.TestCase):
self.assertEqual("auth_url1", ctx.auth_url)
self.assertEqual("domain_id1", ctx.domain_id)
self.assertEqual("domain_name1", ctx.domain_name)
self.assertEqual("user1", ctx.user)
self.assertEqual("user1", ctx.user_name)
self.assertEqual("user-id1", ctx.user_id)
self.assertEqual("tenant1", ctx.project)
self.assertEqual("tenant1", ctx.project_name)
self.assertEqual("tenant-id1", ctx.project_id)
self.assertTrue(ctx.is_admin)
self.assertTrue(ctx.is_public_api)
@ -62,10 +62,10 @@ class ContextTestCase(base.TestCase):
self.assertEqual(ctx.auth_url, ctx2.auth_url)
self.assertEqual(ctx.domain_id, ctx2.domain_id)
self.assertEqual(ctx.domain_name, ctx2.domain_name)
self.assertEqual(ctx.user, ctx2.user)
self.assertEqual(ctx.user_name, ctx2.user_name)
self.assertEqual(ctx.user_id, ctx2.user_id)
self.assertEqual(ctx.tenant, ctx2.tenant)
self.assertEqual(ctx.project, ctx2.project)
self.assertEqual(ctx.project_name, ctx2.project_name)
self.assertEqual(ctx.project_id, ctx2.project_id)
self.assertEqual(ctx.is_admin, ctx2.is_admin)
self.assertEqual(ctx.is_public_api, ctx2.is_public_api)