Fix context warning spam of scheduler and share logs

Manila share and scheduler logs are littered with warnings about dropped
kwargs when creating request context. Here is an example:

2016-04-18 17:08:16.103 WARNING manila.context [-] Arguments dropped
when creating context: {u'read_only': False, u'domain': None,
u'show_deleted': False, u'user_identity':
u'6133ebc001384629a4a9ecfc630bb26b 21b76a623d104713845b686526c10720 - -
-', u'project_domain': None, u'resource_uuid': None, u'user_domain':
None}.

These are currently "just noise". Their meaning is not evident without
code study, and they cause confusion and alarm to cloud operators,
resulting in unnecessary support calls and ultimately in a reduction
in value and credibility of our logging system.

In manila share log these messages occur on every CRUD operation.
In manila scheduler the situation is even worse as they occur on every
periodic capabilities/capacity update.

Fix this spam by only sending this warning when we receive truly
unexpected kwargs by following the nova fix [1] for essentially
the same issue in that project.

Closes-Bug: #1582346

[1] Ia47d4909d2656d6fc4c1179659b8098bba3235d3

Change-Id: Ieba91b42ef680b353dbb326667580bf482ff8d48
This commit is contained in:
Tom Barron 2016-05-14 08:34:08 -04:00
parent 5c961ab615
commit 4c3c7e5fa4
2 changed files with 50 additions and 9 deletions

View File

@ -56,18 +56,25 @@ class RequestContext(context.RequestContext):
user = kwargs.pop('user', None)
tenant = kwargs.pop('tenant', None)
super(RequestContext, self).__init__(
auth_token=auth_token,
user=user_id or user,
tenant=project_id or tenant,
domain=kwargs.pop('domain', None),
user_domain=kwargs.pop('user_domain', None),
project_domain=kwargs.pop('project_domain', None),
is_admin=is_admin,
read_only=kwargs.pop('read_only', False),
show_deleted=kwargs.pop('show_deleted', False),
request_id=request_id,
resource_uuid=kwargs.pop('resource_uuid', None),
overwrite=overwrite,
roles=roles)
kwargs.pop('user_identity', None)
if kwargs:
LOG.warning(_LW('Arguments dropped when creating context: %s.'),
str(kwargs))
super(RequestContext, self).__init__(auth_token=auth_token,
user=user_id or user,
tenant=project_id or tenant,
is_admin=is_admin,
request_id=request_id,
overwrite=overwrite,
roles=roles)
self.user_id = self.user
self.project_id = self.tenant

View File

@ -12,6 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from manila import context
from manila import test
@ -85,6 +87,38 @@ class ContextTestCase(test.TestCase):
self.assertNotIn("'user': 'user'", info['log_msg'])
self.assertNotIn("'tenant': 'project'", info['log_msg'])
def test_normal_kwargs_are_used_so_not_logged(self):
mock_log = self.mock_object(context.LOG, 'warning', mock.Mock())
# Supply the kwargs normally supplied to RequestContext
# for scheduler and share service.
context.RequestContext('user',
'project',
is_admin=None,
read_deleted="no",
roles=None,
remote_address=None,
timestamp=None,
request_id=None,
auth_token=None,
overwrite=True,
quota_class=None,
service_catalog=None,
read_only=False,
domain=None,
show_deleted=False,
user_identity='- - - - -',
project_domain=None,
resource_uuid=None,
user_domain=None,
user='user',
tenant='project')
# Assert that there is no log warning that there were
# extra kwargs that were dropped.
self.assertEqual(0, mock_log.call_count)
def test_to_dict_works_w_missing_manila_context_attributes(self):
manila_context_attributes = ['user_id', 'project_id', 'read_deleted',
'remote_address', 'timestamp',