Use tobiko own config options to configure logging

Because devstack configures 'oslo.log' python based projects
to be used with journalctl by default configures logging
handlers not to add timestamp in logging messages.

This causes tobiko upstream jobs to loose this valueable
info in tobiko report files. In order to have this
conflicting configuration not affected by DevStack scripts
let make tobiko test cases use special options that are
not the same as default oslo.log based projects.

New configuration options are:

 [logging]
 # Default logging line format string
 line_format = %(asctime)s.%(msecs)03d %(process)d %(levelname)s %(name)s - %(message)s

 # Default logging date format string
 date_format = %Y-%m-%d %H:%M:%S

Change-Id: I1d41a4398c3c1f8667faaccca32f77491cd5305f
This commit is contained in:
Federico Ressi 2021-09-28 11:08:39 +02:00
parent 97f06d6d7e
commit f08f967085
3 changed files with 40 additions and 28 deletions

View File

@ -46,7 +46,14 @@ LOGGING_CONF_GROUP_NAME = "logging"
LOGGING_OPTIONS = [
cfg.BoolOpt('capture_log',
default=True,
help="Whenever to capture LOG during test case execution"),
help="Whenever to report debugging log lines"),
cfg.StrOpt('line_format',
default=('%(asctime)s.%(msecs)03d %(process)d %(levelname)s '
'%(name)s - %(message)s'),
help='Default logging line format string'),
cfg.StrOpt('date_format',
default='%Y-%m-%d %H:%M:%S',
help='Default logging date format string'),
]
HTTP_CONF_GROUP_NAME = "http"

View File

@ -50,35 +50,35 @@ def configure_metadata(config):
def configure_caplog(config):
tobiko_config = tobiko.tobiko_config()
if tobiko_config.logging.capture_log is True:
if tobiko_config.logging.capture_log:
if tobiko_config.debug:
default = 'DEBUG'
level = 'DEBUG'
else:
default = 'INFO'
level = 'INFO'
else:
default = 'FATAL'
level = 'FATAL'
for key in ['log_level',
'log_file_level',
'log_cli_level']:
set_default_inicfg(config, key, default)
set_default_inicfg(config, key, level)
default = tobiko_config.logging_default_format_string
if default:
line_format: str = tobiko_config.logging.line_format
if line_format:
# instance and color are not supported by pytest
default = default.replace('%(instance)s', '')
default = default.replace('%(color)s', '')
if default:
line_format = line_format.replace('%(instance)s', '')
line_format = line_format.replace('%(color)s', '')
if line_format:
for key in ['log_format',
'log_file_format',
'log_cli_format']:
set_default_inicfg(config, key, default)
set_default_inicfg(config, key, line_format)
default = tobiko_config.log_date_format
if default:
date_format = tobiko_config.logging.date_format
if date_format:
for key in ['log_date_format',
'log_file_date_format',
'log_cli_date_format']:
set_default_inicfg(config, key, default)
set_default_inicfg(config, key, date_format)
def configure_junitxml(config):
@ -87,10 +87,8 @@ def configure_junitxml(config):
def set_default_inicfg(config, key, default):
value = config.inicfg.setdefault(key, default)
if value != default:
LOG.debug(f"Set default inicfg: {key} = {value}")
else:
LOG.debug(f"Keep existing inicfg: {key} = {value}")
if value == default:
LOG.debug(f"Set default inicfg: {key} = {value!r}")
class TestRunnerTimeoutManager(tobiko.SharedFixture):

View File

@ -55,25 +55,32 @@ class CaplogTest(unit.TobikoUnitTest):
self.assertEqual('FATAL', pytest_config.inicfg['log_level'])
def test_configure_caplog_log_format(self):
self.patch_caplog_config(log_format='<some-format>')
self.patch_caplog_config(line_format='<some-format>')
pytest_config = mock.MagicMock(inicfg={})
conftest.configure_caplog(pytest_config)
self.assertEqual('<some-format>', pytest_config.inicfg['log_format'])
def test_configure_caplog_log_date_format(self):
self.patch_caplog_config(log_date_format='<some-format>')
def test_configure_caplog_date_format(self):
self.patch_caplog_config(date_format='<some-format>')
pytest_config = mock.MagicMock(inicfg={})
conftest.configure_caplog(pytest_config)
self.assertEqual('<some-format>',
pytest_config.inicfg['log_date_format'])
def patch_caplog_config(self, capture_log=False, debug=False,
log_format=None, log_date_format=None):
def patch_caplog_config(self,
capture_log: bool = None,
debug: bool = None,
line_format: str = None,
date_format: str = None):
tobiko_config = self.patch(tobiko, 'tobiko_config').return_value
tobiko_config.logging.capture_log = capture_log
tobiko_config.debug = debug
tobiko_config.logging_default_format_string = log_format
tobiko_config.log_date_format = log_date_format
if capture_log is not None:
tobiko_config.logging.capture_log = capture_log
if debug is not None:
tobiko_config.debug = debug
if line_format is not None:
tobiko_config.logging.line_format = line_format
if date_format is not None:
tobiko_config.logging.date_format = date_format
class TimeoutTest(unit.TobikoUnitTest):