URL: https://github.com/freeipa/freeipa/pull/1098 Author: tomaskrizek Title: #1098: [ipa-4-5] Backport 7083 Action: opened
PR body: """ Original PR: #956 """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/1098/head:pr1098 git checkout pr1098
From f701f3626c51d54835cefd3152d95c9ae6228bd6 Mon Sep 17 00:00:00 2001 From: Petr Vobornik <pvobo...@redhat.com> Date: Thu, 3 Aug 2017 15:48:33 +0200 Subject: [PATCH 1/2] 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 --- install/tools/ipa-replica-conncheck | 7 ++++++- ipapython/ipautil.py | 16 +++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/install/tools/ipa-replica-conncheck b/install/tools/ipa-replica-conncheck index 9b92de3f66..5d99524438 100755 --- a/install/tools/ipa-replica-conncheck +++ b/install/tools/ipa-replica-conncheck @@ -378,11 +378,16 @@ class PortResponder(threading.Thread): def port_check(host, port_list): ports_failed = [] ports_udp_warning = [] # conncheck could not verify that port is open + log_level = { + SOCK_DGRAM: logging.WARNING, + SOCK_STREAM: logging.ERROR + } for port in port_list: try: port_open = ipautil.host_port_open( host, port.port, port.port_type, - socket_timeout=CONNECT_TIMEOUT, log_errors=True) + socket_timeout=CONNECT_TIMEOUT, log_errors=True, + log_level=log_level[port.port_type]) except socket.gaierror: raise RuntimeError("Port check failed! Unable to resolve host name '%s'" % host) if port_open: diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index 1bb48d4fc2..fc2cabae6b 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -959,7 +959,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 @@ -981,23 +982,16 @@ def host_port_open(host, port, socket_type=socket.SOCK_STREAM, s.connect(sa) if socket_type == socket.SOCK_DGRAM: - s.send('') + s.send(b'') 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: - root_logger.warning(msg) - else: - root_logger.error(msg) + root_logger.log(log_level, msg) finally: if s is not None: s.close() From 3305f92d7c1b9f61e72d933eab05a5260d6507e4 Mon Sep 17 00:00:00 2001 From: Petr Vobornik <pvobo...@redhat.com> Date: Thu, 3 Aug 2017 16:03:29 +0200 Subject: [PATCH 2/2] log progress of wait_for_open_ports To know what to focus on when some check fail. E.g. to detect that IPv6 address or its resolution for localhost is misconfigured. https://pagure.io/freeipa/issue/7083 --- ipapython/ipautil.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index fc2cabae6b..eb1af5146b 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -1223,15 +1223,20 @@ def wait_for_open_ports(host, ports, timeout=0): op_timeout = time.time() + timeout for port in ports: + logger.debug('waiting for port: %s', port) + log_error = True while True: - port_open = host_port_open(host, port) + port_open = host_port_open(host, port, log_errors=log_error) + log_error = False # Log only first err so that the log is readable if port_open: + logger.debug('SUCCESS: port: %s', port) break if timeout and time.time() > op_timeout: # timeout exceeded raise socket.timeout("Timeout exceeded") time.sleep(1) + def wait_for_open_socket(socket_name, timeout=0): """ Wait until the specified socket on the local host is open. Timeout
_______________________________________________ FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org