]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix format errors seen in rpc logging
authorMaru Newby <marun@redhat.com>
Mon, 25 Nov 2013 17:35:54 +0000 (17:35 +0000)
committerMaru Newby <marun@redhat.com>
Wed, 27 Nov 2013 07:51:13 +0000 (07:51 +0000)
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

neutron/context.py
neutron/tests/unit/test_neutron_context.py

index 6cd9311e4b14266585eaf165bc650e5130127a09..1dadd4c4b038fb995e6ed92eaed2249e8a0034bf 100644 (file)
@@ -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,
                 }
 
index 58a26ea9d9b0ab463c98f0220ad06f31f838df1a..a756e8f2bbfa688c3a2e5698a69d3aceb5d3de3d 100644 (file)
@@ -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'