Remove fallback for old oslo.context

The get_logging_values method was added in oslo.context 2.0.0[1].

[1] 22ad2c2c591f16012a75c99bd11b2f30d35bffff

Closes-Bug: #1715148
Change-Id: Idb31334674805e821cf5c34b9553b7002d158b6c
This commit is contained in:
Takashi Kajinami 2024-03-31 01:15:10 +09:00
parent a1fe1b9cfb
commit 65e33466ae
3 changed files with 2 additions and 38 deletions

View File

@ -11,7 +11,6 @@
# under the License.
import datetime
import debtcollector
import functools
import io
import itertools
@ -33,13 +32,6 @@ from oslo_utils import encodeutils
def _dictify_context(context):
if getattr(context, 'get_logging_values', None):
return context.get_logging_values()
elif getattr(context, 'to_dict', None):
debtcollector.deprecate(
'The RequestContext.get_logging_values() '
'method should be defined for logging context specific '
'information. The to_dict() method is deprecated '
'for oslo.log use.', version='3.8.0', removal_version='5.0.0')
return context.to_dict()
# This dict only style logging format will become deprecated
# when projects using a dictionary object for context are updated
elif isinstance(context, dict):

View File

@ -16,7 +16,6 @@
import logging
import sys
from unittest import mock
from oslo_config import cfg
from oslo_config import fixture as config_fixture
@ -37,17 +36,6 @@ def _fake_context():
return ctxt
class AlternativeRequestContext(object):
def __init__(self, user=None, tenant=None):
self.user = user
self.tenant = tenant
def to_dict(self):
return {'user': self.user,
'tenant': self.tenant}
class FormatterTest(test_base.BaseTestCase):
def setUp(self):
@ -66,29 +54,14 @@ class FormatterTest(test_base.BaseTestCase):
def test_dictify_context_empty(self):
self.assertEqual({}, formatters._dictify_context(None))
@mock.patch("debtcollector.deprecate")
def test_dictify_context_with_dict(self, mock_deprecate):
def test_dictify_context_with_dict(self):
d = {"user": "user"}
self.assertEqual(d, formatters._dictify_context(d))
mock_deprecate.assert_not_called()
@mock.patch("debtcollector.deprecate")
def test_dictify_context_with_context(self, mock_deprecate):
def test_dictify_context_with_context(self):
ctxt = _fake_context()
self.assertEqual(ctxt.get_logging_values(),
formatters._dictify_context(ctxt))
mock_deprecate.assert_not_called()
@mock.patch("debtcollector.deprecate")
def test_dictify_context_without_get_logging_values(self, mock_deprecate):
ctxt = AlternativeRequestContext(user="user", tenant="tenant")
d = {"user": "user", "tenant": "tenant"}
self.assertEqual(d, formatters._dictify_context(ctxt))
mock_deprecate.assert_called_with(
'The RequestContext.get_logging_values() '
'method should be defined for logging context specific '
'information. The to_dict() method is deprecated '
'for oslo.log use.', removal_version='5.0.0', version='3.8.0')
# Test for https://bugs.python.org/issue28603

View File

@ -4,6 +4,5 @@ oslo.context>=2.21.0 # Apache-2.0
oslo.i18n>=3.20.0 # Apache-2.0
oslo.utils>=3.36.0 # Apache-2.0
oslo.serialization>=2.25.0 # Apache-2.0
debtcollector>=1.19.0 # Apache-2.0
pyinotify>=0.9.6;sys_platform!='win32' and sys_platform!='darwin' and sys_platform!='sunos5' # MIT
python-dateutil>=2.7.0 # BSD