diff options
author | Alan Bishop <abishop@redhat.com> | 2022-02-05 12:47:09 -0800 |
---|---|---|
committer | Alan Bishop <abishop@redhat.com> | 2022-02-05 12:58:43 -0800 |
commit | 650ce7d313e00525c4391692fbdc4cba529e11ea (patch) | |
tree | 5b275cfd521087082b3f52410cb0b6db4f1198f3 | |
parent | 27d159b4d6364ea6284c6e1e9aa4abcda6d536fe (diff) | |
download | oslo-log-650ce7d313e00525c4391692fbdc4cba529e11ea.tar.gz |
Use project when logging the user identity
The logging_user_identity_format option's default value is changed
to reference the project instead of the tenant. This is necessary
because I2fded6f3476df1fb8c4e042ef28ed8ccb7ab0737 removed the tenant
argument from request contexts.
Related-Bug: #1505827
Change-Id: Id6d4b6eaa2b96ba5bd53e8b2dae5d9eea13b25d9
-rw-r--r-- | oslo_log/_options.py | 2 | ||||
-rw-r--r-- | oslo_log/tests/unit/test_log.py | 42 | ||||
-rw-r--r-- | releasenotes/notes/use-project-in-user-identity-93fd6e0a2e434a6f.yaml | 5 |
3 files changed, 22 insertions, 27 deletions
diff --git a/oslo_log/_options.py b/oslo_log/_options.py index 9138368..141c0d4 100644 --- a/oslo_log/_options.py +++ b/oslo_log/_options.py @@ -167,7 +167,7 @@ log_opts = [ help='Prefix each line of exception output with this format. ' 'Used by oslo_log.formatters.ContextFormatter'), cfg.StrOpt('logging_user_identity_format', - default='%(user)s %(tenant)s ' + default='%(user)s %(project)s ' '%(domain)s %(user_domain)s %(project_domain)s', help='Defines the format string for %(user_identity)s that ' 'is used in logging_context_format_string. ' diff --git a/oslo_log/tests/unit/test_log.py b/oslo_log/tests/unit/test_log.py index 723cffb..2159315 100644 --- a/oslo_log/tests/unit/test_log.py +++ b/oslo_log/tests/unit/test_log.py @@ -69,26 +69,14 @@ handlers= def _fake_context(): - ctxt = context.RequestContext(1, 1, overwrite=True) - ctxt.user = 'myuser' - ctxt.tenant = 'mytenant' - ctxt.domain = 'mydomain' - ctxt.project_domain = 'myprojectdomain' - ctxt.user_domain = 'myuserdomain' - - return ctxt - - -def _fake_new_context(): - # New style contexts have a user_name / project_name, this is done - # distinctly from the above context to not have to rewrite all the - # other tests. - ctxt = context.RequestContext(1, 1, overwrite=True) - ctxt.user_name = 'myuser' - ctxt.project_name = 'mytenant' - ctxt.domain = 'mydomain' - ctxt.project_domain = 'myprojectdomain' - ctxt.user_domain = 'myuserdomain' + ctxt = context.RequestContext(user_id="myuser", + user_name="myuser", + domain="mydomain", + project_id="mytenant", + project_name="mytenant", + project_domain_id="mydomain", + user_domain_id="myuserdomain", + overwrite=True) return ctxt @@ -108,7 +96,7 @@ class CommonLoggerTestsMixIn(object): log.register_options(self.config_fixture.conf) self.config(logging_context_format_string='%(asctime)s %(levelname)s ' '%(name)s [%(request_id)s ' - '%(user)s %(tenant)s] ' + '%(user)s %(project)s] ' '%(message)s') self.log = None log._setup_logging_from_conf(self.config_fixture.conf, 'test', 'test') @@ -405,7 +393,7 @@ class OSJournalHandlerTestCase(BaseTestCase): def test_emit(self): logger = log.getLogger('nova-test.foo') - local_context = _fake_new_context() + local_context = _fake_context() logger.info("Foo", context=local_context) self.assertEqual( mock.call(mock.ANY, CODE_FILE=mock.ANY, CODE_FUNC='test_emit', @@ -414,6 +402,7 @@ class OSJournalHandlerTestCase(BaseTestCase): SYSLOG_FACILITY=syslog.LOG_USER, SYSLOG_IDENTIFIER=mock.ANY, REQUEST_ID=mock.ANY, + PROJECT_ID='mytenant', PROJECT_NAME='mytenant', PROCESS_NAME='MainProcess', THREAD_NAME='MainThread', @@ -432,7 +421,7 @@ class OSJournalHandlerTestCase(BaseTestCase): def test_emit_exception(self): logger = log.getLogger('nova-exception.foo') - local_context = _fake_new_context() + local_context = _fake_context() try: raise Exception("Some exception") except Exception: @@ -447,6 +436,7 @@ class OSJournalHandlerTestCase(BaseTestCase): REQUEST_ID=mock.ANY, EXCEPTION_INFO=mock.ANY, EXCEPTION_TEXT=mock.ANY, + PROJECT_ID='mytenant', PROJECT_NAME='mytenant', PROCESS_NAME='MainProcess', THREAD_NAME='MainThread', @@ -968,7 +958,7 @@ class ContextFormatterTestCase(LogTestBase): message = 'test' self.log.info(message, context=ctxt) expected = ("HAS CONTEXT [%s %s %s %s %s %s]: %s\n" % - (ctxt.request_id, ctxt.user, ctxt.tenant, ctxt.domain, + (ctxt.request_id, ctxt.user, ctxt.project_id, ctxt.domain, ctxt.user_domain, ctxt.project_domain, str(message))) self.assertEqual(expected, self.stream.getvalue()) @@ -979,13 +969,13 @@ class ContextFormatterTestCase(LogTestBase): "%(user_identity)s]: " "%(message)s", logging_user_identity_format="%(user)s " - "%(tenant)s") + "%(project)s") ctxt = _fake_context() ctxt.request_id = '99' message = 'test' self.log.info(message, context=ctxt) expected = ("HAS CONTEXT [%s %s %s]: %s\n" % - (ctxt.request_id, ctxt.user, ctxt.tenant, + (ctxt.request_id, ctxt.user, ctxt.project_id, str(message))) self.assertEqual(expected, self.stream.getvalue()) diff --git a/releasenotes/notes/use-project-in-user-identity-93fd6e0a2e434a6f.yaml b/releasenotes/notes/use-project-in-user-identity-93fd6e0a2e434a6f.yaml new file mode 100644 index 0000000..3aa9494 --- /dev/null +++ b/releasenotes/notes/use-project-in-user-identity-93fd6e0a2e434a6f.yaml @@ -0,0 +1,5 @@ +--- +upgrade: + - | + The ``logging_user_identity_format`` option's default value is updated to + replace the obsolete ``tenant`` argument with ``project``. |