From: Aleš Date: Thu, 27 Jan 2022 11:04:15 +0000 (+0100) Subject: manager: codecheck fixes X-Git-Tag: v6.0.0a1~45^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f07494b020fa1661d037ba7370b71bf4a83ae21;p=thirdparty%2Fknot-resolver.git manager: codecheck fixes --- diff --git a/manager/knot_resolver_manager/datamodel/network_schema.py b/manager/knot_resolver_manager/datamodel/network_schema.py index 0e1207931..f6af86c1d 100644 --- a/manager/knot_resolver_manager/datamodel/network_schema.py +++ b/manager/knot_resolver_manager/datamodel/network_schema.py @@ -71,7 +71,7 @@ class ListenSchema(SchemaNode): raise ValueError( "The '@' syntax must be used either for all or none of the IP addresses in the list." ) - port_set = True if addr.port else False + port_set = bool(addr.port) elif isinstance(origin.ip_address, IPAddressOptionalPort) and origin.ip_address.port and origin.port: raise ValueError("The port number is defined in two places ('port' option and '@' syntax).") return origin.ip_address @@ -86,7 +86,7 @@ class ListenSchema(SchemaNode): raise ValueError( "The '@' syntax must be used either for all or none of the interface in the list." ) - port_set = True if intrfc.port else False + port_set = bool(intrfc.port) elif isinstance(origin.interface, InterfaceOptionalPort) and origin.interface.port and origin.port: raise ValueError("The port number is defined in two places ('port' option and '@' syntax).") return origin.interface diff --git a/manager/knot_resolver_manager/datamodel/types.py b/manager/knot_resolver_manager/datamodel/types.py index a35fcc96f..99fdee4f8 100644 --- a/manager/knot_resolver_manager/datamodel/types.py +++ b/manager/knot_resolver_manager/datamodel/types.py @@ -193,6 +193,9 @@ class _StrCustomBase(CustomValueType): _value: str + def __int__(self) -> int: + raise ValueError("Can't convert string to an integer.") + def __str__(self) -> str: return self._value @@ -227,6 +230,7 @@ class _IntRangeBase(_IntCustomBase): _max: int def __init__(self, source_value: Any, object_path: str = "/") -> None: + super().__init__(source_value) if isinstance(source_value, int): if not self._min <= source_value <= self._max: raise SchemaException( @@ -514,6 +518,7 @@ class IPAddressOptionalPort(_StrCustomBase): port: Optional[PortNumber] = None def __init__(self, source_value: Any, object_path: str = "/") -> None: + super().__init__(source_value) if isinstance(source_value, str): parts = source_value.split("@") if 0 < len(parts) < 3: diff --git a/manager/knot_resolver_manager/server.py b/manager/knot_resolver_manager/server.py index 50eda8e99..102f4bcf6 100644 --- a/manager/knot_resolver_manager/server.py +++ b/manager/knot_resolver_manager/server.py @@ -227,7 +227,7 @@ class Server: nsite = web.TCPSite(self.runner, str(mgn.ip_address.addr), int(mgn.ip_address.port)) logger.info(f"Starting API HTTP server on http://{mgn.ip_address.addr}:{mgn.ip_address.port}") else: - raise KresManagerException(f"Requested API on unsupported configuration format.") + raise KresManagerException("Requested API on unsupported configuration format.") await nsite.start() # stop the old listen