Merge "Provide an API to let tempest control the log file"
This commit is contained in:
commit
0fe64f59bb
@ -246,6 +246,20 @@ def set_defaults(logging_context_format_string=None,
|
||||
logging_context_format_string=logging_context_format_string)
|
||||
|
||||
|
||||
def tempest_set_log_file(filename):
|
||||
"""Provide an API for tempest to set the logging filename.
|
||||
|
||||
.. warning:: Only Tempest should use this function.
|
||||
|
||||
We don't want applications to set a default log file, so we don't
|
||||
want this in set_defaults(). Because tempest doesn't use a
|
||||
configuration file we don't have another convenient way to safely
|
||||
set the log file default.
|
||||
|
||||
"""
|
||||
cfg.set_defaults(_options.logging_cli_opts, log_file=filename)
|
||||
|
||||
|
||||
def _find_facility_from_conf(conf):
|
||||
facility_names = logging.handlers.SysLogHandler.facility_names
|
||||
facility = getattr(logging.handlers.SysLogHandler,
|
||||
|
@ -563,6 +563,7 @@ class SetDefaultsTestCase(BaseTestCase):
|
||||
super(SetDefaultsTestCase, self).setUp()
|
||||
self.conf = self.TestConfigOpts()
|
||||
self.conf.register_opts(_options.log_opts)
|
||||
self.conf.register_cli_opts(_options.logging_cli_opts)
|
||||
|
||||
self._orig_defaults = dict([(o.dest, o.default)
|
||||
for o in _options.log_opts])
|
||||
@ -593,6 +594,17 @@ class SetDefaultsTestCase(BaseTestCase):
|
||||
self.assertEqual(['foo=bar'], self.conf.default_log_levels)
|
||||
self.assertIsNotNone(self.conf.logging_context_format_string)
|
||||
|
||||
def test_tempest_set_log_file(self):
|
||||
log.tempest_set_log_file('foo.log')
|
||||
log.set_defaults()
|
||||
self.conf([])
|
||||
self.assertEqual('foo.log', self.conf.log_file)
|
||||
|
||||
def test_log_file_defaults_to_none(self):
|
||||
log.set_defaults()
|
||||
self.conf([])
|
||||
self.assertEqual(None, self.conf.log_file)
|
||||
|
||||
|
||||
class LogConfigOptsTestCase(BaseTestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user