Skip to content

Commit

Permalink
Merge pull request #49726 from jettero/why-getaddrinfo
Browse files Browse the repository at this point in the history
catch socket.error too; and reflow for readability (why list?)
  • Loading branch information
rallytime authored Nov 12, 2018
2 parents 8bebb19 + ed13435 commit c64607a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions salt/utils/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,8 @@ def get_fqhostname():
'''
Returns the fully qualified hostname
'''
l = [socket.getfqdn()]

# try socket.getaddrinfo
# try getaddrinfo()
fqdn = None
try:
addrinfo = socket.getaddrinfo(
socket.gethostname(), 0, socket.AF_UNSPEC, socket.SOCK_STREAM,
Expand All @@ -210,12 +209,16 @@ def get_fqhostname():
# info struct [family, socktype, proto, canonname, sockaddr]
# On Windows `canonname` can be an empty string
# This can cause the function to return `None`
if len(info) >= 4 and info[3]:
l = [info[3]]
if len(info) > 3 and info[3]:
fqdn = info[3]
break
except socket.gaierror:
pass

return l and l[0] or None
pass # NOTE: this used to log.error() but it was later disabled
except socket.error as err:
log.debug('socket.getaddrinfo() failure while finding fqdn: %s', err)
if fqdn is None:
fqdn = socket.getfqdn()
return fqdn


def ip_to_host(ip):
Expand Down

0 comments on commit c64607a

Please sign in to comment.