When the python unbound library is not installed, dns_resolve.resolve() returns None for hostnames, causing all hostname-based TCP connections to silently fail. This affects services like neutron-ovn-metadata-agent that use hostname-based connection strings (e.g. tcp:hostname:6642).
Add a fallback to socket.getaddrinfo() which uses the system resolver (/etc/hosts, nsswitch.conf, system DNS) when unbound is unavailable or fails to resolve. Signed-off-by: wlswo <[email protected]> Signed-off-by: wlswo <[email protected]> --- python/ovs/socket_util.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/python/ovs/socket_util.py b/python/ovs/socket_util.py index a26298b75..93764568b 100644 --- a/python/ovs/socket_util.py +++ b/python/ovs/socket_util.py @@ -235,6 +235,17 @@ def _inet_parse_active(target, default_port): host_name = str(ipaddress.ip_address(host_name)) except ValueError: host_name = dns_resolve.resolve(host_name) + if not host_name: + # Fallback to the system resolver (e.g. /etc/hosts, system DNS) + # when the unbound library is not available. + try: + result = socket.getaddrinfo( + ":".join(address[0:-1]).lstrip('[').rstrip(']'), + None, 0, socket.SOCK_STREAM) + if result: + host_name = result[0][4][0] + except socket.gaierror: + pass if not host_name: raise ValueError("%s: bad peer name format" % target) return (host_name, port) -- 2.40.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
