From cc72db67e2eaede577c3129d572b85e9c2ba593c Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Thu, 3 Aug 2017 15:48:33 +0200 Subject: control logging of host_port_open from caller host_port_open copied logging behavior of ipa-replica-conncheck utility which doesn't make it much reusable. Now log level can be controlled from caller so other callers might use other logging level without host_port_open guessing what was the intention. https://pagure.io/freeipa/issue/7083 Reviewed-By: Tomas Krizek --- ipapython/ipautil.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'ipapython') diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index d2b5abb08..c8069d963 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -960,7 +960,8 @@ def user_input(prompt, default = None, allow_empty = True): def host_port_open(host, port, socket_type=socket.SOCK_STREAM, - socket_timeout=None, log_errors=False): + socket_timeout=None, log_errors=False, + log_level=logging.DEBUG): """ host: either hostname or IP address; if hostname is provided, port MUST be open on ALL resolved IPs @@ -986,19 +987,12 @@ def host_port_open(host, port, socket_type=socket.SOCK_STREAM, s.recv(512) except socket.error: port_open = False - if log_errors: - msg = ('Failed to connect to port %(port)d %(proto)s on ' + msg = ('Failed to connect to port %(port)s %(proto)s on ' '%(addr)s' % dict(port=port, proto=PROTOCOL_NAMES[socket_type], addr=sa[0])) - - # Do not log udp failures as errors (to be consistent with - # the rest of the code that checks for open ports) - if socket_type == socket.SOCK_DGRAM: - logger.warning('%s', msg) - else: - logger.error('%s', msg) + logger.log(log_level, msg) finally: if s is not None: s.close() -- cgit