ceph/teuthology/orchestra/monkey.py

48 lines
1.1 KiB
Python
Raw Normal View History

2011-05-19 17:18:57 +00:00
import logging
2011-05-19 17:19:16 +00:00
log = logging.getLogger(__name__)
2011-05-19 17:17:51 +00:00
def patch_001_paramiko_deprecation():
"""
Silence an an unhelpful DeprecationWarning triggered by Paramiko.
Not strictly a monkeypatch.
"""
import warnings
warnings.filterwarnings(
category=DeprecationWarning,
message='This application uses RandomPool,',
action='ignore',
)
2011-05-19 17:18:57 +00:00
def patch_100_paramiko_log():
"""
Silence some noise paramiko likes to log.
Not strictly a monkeypatch.
"""
logging.getLogger('paramiko.transport').setLevel(logging.WARNING)
2011-05-19 17:17:03 +00:00
def patch_100_logger_getChild():
2011-05-18 21:46:49 +00:00
"""
Imitate Python 2.7 feature Logger.getChild.
"""
import logging
if not hasattr(logging.Logger, 'getChild'):
def getChild(self, name):
return logging.getLogger('.'.join([self.name, name]))
logging.Logger.getChild = getChild
def patch_all():
"""
Run all the patch_* functions in this module.
"""
monkeys = [(k,v) for (k,v) in globals().iteritems() if k.startswith('patch_') and k != 'patch_all']
2011-05-19 17:17:03 +00:00
monkeys.sort()
2011-05-18 21:46:49 +00:00
for k,v in monkeys:
2011-05-19 17:19:16 +00:00
log.debug('Patching %s', k)
2011-05-18 21:46:49 +00:00
v()