diff --git a/VERSION b/VERSION index b60d719..7ada0d3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.8.4 +0.8.5 diff --git a/src/wechaty_puppet_service/utils.py b/src/wechaty_puppet_service/utils.py index be32db9..4e40a95 100644 --- a/src/wechaty_puppet_service/utils.py +++ b/src/wechaty_puppet_service/utils.py @@ -25,16 +25,20 @@ 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 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,16 +53,32 @@ 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) 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: