mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
Merge pull request #1996 from AlanCoding/null_handler_again
Interpret null protocol as logging.NullHandler
This commit is contained in:
@@ -127,6 +127,17 @@ def test_invalid_kwarg_to_real_handler():
|
|||||||
assert not hasattr(handler, 'verify_cert')
|
assert not hasattr(handler, 'verify_cert')
|
||||||
|
|
||||||
|
|
||||||
|
def test_protocol_not_specified():
|
||||||
|
settings = LazySettings()
|
||||||
|
settings.configure(**{
|
||||||
|
'LOG_AGGREGATOR_HOST': 'https://server.invalid',
|
||||||
|
'LOG_AGGREGATOR_PORT': 22222,
|
||||||
|
'LOG_AGGREGATOR_PROTOCOL': None # awx/settings/defaults.py
|
||||||
|
})
|
||||||
|
handler = AWXProxyHandler().get_handler(custom_settings=settings)
|
||||||
|
assert isinstance(handler, logging.NullHandler)
|
||||||
|
|
||||||
|
|
||||||
def test_base_logging_handler_emit_system_tracking(dummy_log_record):
|
def test_base_logging_handler_emit_system_tracking(dummy_log_record):
|
||||||
handler = BaseHandler(host='127.0.0.1', indv_facts=True)
|
handler = BaseHandler(host='127.0.0.1', indv_facts=True)
|
||||||
handler.setFormatter(LogstashFormatter())
|
handler.setFormatter(LogstashFormatter())
|
||||||
|
|||||||
@@ -257,6 +257,15 @@ class UDPHandler(BaseHandler):
|
|||||||
return SocketResult(True, reason=self.message)
|
return SocketResult(True, reason=self.message)
|
||||||
|
|
||||||
|
|
||||||
|
class AWXNullHandler(logging.NullHandler):
|
||||||
|
'''
|
||||||
|
Only additional this does is accept arbitrary __init__ params because
|
||||||
|
the proxy handler does not (yet) work with arbitrary handler classes
|
||||||
|
'''
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super(AWXNullHandler, self).__init__()
|
||||||
|
|
||||||
|
|
||||||
HANDLER_MAPPING = {
|
HANDLER_MAPPING = {
|
||||||
'https': BaseHTTPSHandler,
|
'https': BaseHTTPSHandler,
|
||||||
'tcp': TCPHandler,
|
'tcp': TCPHandler,
|
||||||
@@ -285,7 +294,7 @@ class AWXProxyHandler(logging.Handler):
|
|||||||
self._old_kwargs = {}
|
self._old_kwargs = {}
|
||||||
|
|
||||||
def get_handler_class(self, protocol):
|
def get_handler_class(self, protocol):
|
||||||
return HANDLER_MAPPING[protocol]
|
return HANDLER_MAPPING.get(protocol, AWXNullHandler)
|
||||||
|
|
||||||
def get_handler(self, custom_settings=None, force_create=False):
|
def get_handler(self, custom_settings=None, force_create=False):
|
||||||
new_kwargs = {}
|
new_kwargs = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user