Reduce Log Size
To reduce the testrepository.subunit output, eliminate debugging logs
from gear.Server and gear.Client.
This is handled via an ENV defined in the tox.ini called `OS_LOG_DEFAULTS`.
Any module can be specified in the typicall python logging format (e.g.
"gear.Server=INFO"). Each entry should be comma separated. For each valid
entry, a fake logger is created with the log level set to that level.
An invalid format will be skipped (expected: `<module name str>=<level_str>`).
An invalid logging level will default to logging.DEBUG.
Specifying OS_LOG_DEFAULT as an ENV var prior to running tox will override
the default values defined in tox.ini.
Change-Id: I893418435c538bfcedb803d12b57832c8111f06f
diff --git a/tests/base.py b/tests/base.py
index e7da178..5b31eea 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -862,6 +862,28 @@
format='%(asctime)s %(name)-32s '
'%(levelname)-8s %(message)s'))
+ # NOTE(notmorgan): Extract logging overrides for specific libraries
+ # from the OS_LOG_DEFAULTS env and create FakeLogger fixtures for
+ # each. This is used to limit the output during test runs from
+ # libraries that zuul depends on such as gear.
+ log_defaults_from_env = os.environ.get('OS_LOG_DEFAULTS')
+
+ if log_defaults_from_env:
+ for default in log_defaults_from_env.split(','):
+ try:
+ name, level_str = default.split('=', 1)
+ level = getattr(logging, level_str, logging.DEBUG)
+ self.useFixture(fixtures.FakeLogger(
+ name=name,
+ level=level,
+ format='%(asctime)s %(name)-32s '
+ '%(levelname)-8s %(message)s'))
+ except ValueError:
+ # NOTE(notmorgan): Invalid format of the log default,
+ # skip and don't try and apply a logger for the
+ # specified module
+ pass
+
class ZuulTestCase(BaseTestCase):