From d734685349f2ba6e440ec9ef2d6d7e690b32ec81 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 3 Aug 2021 23:49:05 +0800 Subject: [PATCH 1/4] add log error for ping exception --- src/wechaty_puppet_service/puppet.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/wechaty_puppet_service/puppet.py b/src/wechaty_puppet_service/puppet.py index 55aa22d..88a4a46 100644 --- a/src/wechaty_puppet_service/puppet.py +++ b/src/wechaty_puppet_service/puppet.py @@ -898,7 +898,13 @@ def _init_puppet(self): log.debug('get puppet ip address : <%s>', data) self.options.end_point = '{ip}:{port}'.format(**data) - if ping(self.options.end_point) is False: + ping_ret = False + try: + ping_ret = ping(self.options.end_point) + except Exception as e: + log.error(f'ping endpoint {self.options.end_point} raise an exception\n{e}') + + if ping_ret is False: raise WechatyPuppetConfigurationError( f"can't not ping endpoint: {self.options.end_point}" ) From 036deed950ec0d49e42ea2611b67222ba7a43dc6 Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 4 Aug 2021 20:37:26 +0800 Subject: [PATCH 2/4] add try catch for ping call --- src/wechaty_puppet_service/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/wechaty_puppet_service/utils.py b/src/wechaty_puppet_service/utils.py index be32db9..d2f46f7 100644 --- a/src/wechaty_puppet_service/utils.py +++ b/src/wechaty_puppet_service/utils.py @@ -25,7 +25,7 @@ import socket from logging import Logger from typing import Optional, Tuple -from ping3 import ping # type: ignore +from ping3 import ping, errors # type: ignore from wechaty_puppet.exceptions import WechatyPuppetConfigurationError # type: ignore @@ -58,7 +58,14 @@ def test_endpoint(end_point: str, log: Logger) -> int: res = True if port is None: - if ping(host) is False: + try: + if ping(host) is False: + res = False + except PermissionError as pe: + log.error(pe) + res = False + except errors.PingError as e: + log.error(f'got a ping error:\n{e}') res = False else: try: From 2e3dce16db84be9ed9806e92ddfd7044339c008c Mon Sep 17 00:00:00 2001 From: Ryan Date: Thu, 5 Aug 2021 21:22:49 +0800 Subject: [PATCH 3/4] improve comment --- src/wechaty_puppet_service/utils.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/wechaty_puppet_service/utils.py b/src/wechaty_puppet_service/utils.py index d2f46f7..4e40a95 100644 --- a/src/wechaty_puppet_service/utils.py +++ b/src/wechaty_puppet_service/utils.py @@ -30,11 +30,15 @@ def extract_host_and_port(url: str) -> Tuple[str, Optional[int]]: - """it shoule be : format, but it can be a service name. - If it's in docker cluster network, the port can be None + """ + It shoule be : format, but it can be a service name. + If it's in docker cluster network, the port can be None. Args: url (str): the service endpoint or names + + Return: + host (str), port (Optional[int]) """ if ':' in url: host, port = url.split(':') @@ -49,9 +53,18 @@ def extract_host_and_port(url: str) -> Tuple[str, Optional[int]]: def test_endpoint(end_point: str, log: Logger) -> int: """ - test_endpoint: - 1.If there is port: telnet - 2.If there is host/domain: ping or + Check end point is valid + Use different method: + 1. If there is port: telnet + 2. If there is host/domain: ping + + Args: + end_point (str): host and port + log (Logger): for debug + + Return: + return True if end point is valid, otherwise False + """ tn = Telnet() host, port = extract_host_and_port(end_point) From 8d01dcc55c1718a460bade08b77defbf7ff17fcc Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 6 Aug 2021 10:33:52 +0800 Subject: [PATCH 4/4] update VERSION file --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index b60d719..7ada0d3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.8.4 +0.8.5