Merge pull request #37144 from DSRCorporation/bugs/36866_salt-minion_communication_broken_2016.3

Bugs/36866 salt minion communication broken 2016.3
This commit is contained in:
Mike Place 2016-10-24 12:19:06 +09:00 committed by GitHub
commit 334313ec64
3 changed files with 44 additions and 42 deletions

View file

@ -24,7 +24,7 @@ import salt.config
import salt.minion
import salt.utils
import salt.utils.event
from salt.utils.network import host_to_ip as _host_to_ip
from salt.utils.network import host_to_ips as _host_to_ips
from salt.utils.network import remote_port_tcp as _remote_port_tcp
from salt.ext.six.moves import zip
from salt.utils.decorators import with_deprecated
@ -1031,7 +1031,7 @@ def master(master=None, connected=True):
# the default publishing port
port = 4505
master_ip = None
master_ips = None
if __salt__['config.get']('publish_port') != '':
port = int(__salt__['config.get']('publish_port'))
@ -1040,20 +1040,22 @@ def master(master=None, connected=True):
# address and try resolving it first. _remote_port_tcp
# only works with IP-addresses.
if master is not None:
tmp_ip = _host_to_ip(master)
if tmp_ip is not None:
master_ip = tmp_ip
master_ips = _host_to_ips(master)
ips = _remote_port_tcp(port)
master_connection_status = False
if master_ips:
ips = _remote_port_tcp(port)
for master_ip in master_ips:
if master_ip in ips:
master_connection_status = True
break
if connected:
if master_ip not in ips:
event = salt.utils.event.get_event('minion', opts=__opts__, listen=False)
event.fire_event({'master': master}, '__master_disconnected')
else:
if master_ip in ips:
event = salt.utils.event.get_event('minion', opts=__opts__, listen=False)
if master_connection_status is not connected:
event = salt.utils.event.get_event('minion', opts=__opts__, listen=False)
if master_connection_status:
event.fire_event({'master': master}, '__master_connected')
else:
event.fire_event({'master': master}, '__master_disconnected')
def ping_master(master):

View file

@ -19,7 +19,7 @@ import salt.utils
import salt.ext.six as six
import salt.utils.event
from salt._compat import subprocess
from salt.utils.network import host_to_ip as _host_to_ip
from salt.utils.network import host_to_ips as _host_to_ips
import os
import ctypes
@ -331,7 +331,7 @@ def master(master=None, connected=True):
# the default publishing port
port = 4505
master_ip = None
master_ips = None
if __salt__['config.get']('publish_port') != '':
port = int(__salt__['config.get']('publish_port'))
@ -340,21 +340,19 @@ def master(master=None, connected=True):
# address and try resolving it first. _remote_port_tcp
# only works with IP-addresses.
if master is not None:
tmp_ip = _host_to_ip(master)
if tmp_ip is not None:
master_ip = tmp_ip
master_ips = _host_to_ips(master)
ips = _win_remotes_on(port)
master_connection_status = False
if master_ips:
ips = _win_remotes_on(port)
for master_ip in master_ips:
if master_ip in ips:
master_connection_status = True
break
if connected:
if master_ip not in ips:
event = salt.utils.event.get_event(
'minion', opts=__opts__, listen=False
)
event.fire_event({'master': master}, '__master_disconnected')
else:
if master_ip in ips:
event = salt.utils.event.get_event(
'minion', opts=__opts__, listen=False
)
if master_connection_status is not connected:
event = salt.utils.event.get_event('minion', opts=__opts__, listen=False)
if master_connection_status:
event.fire_event({'master': master}, '__master_connected')
else:
event.fire_event({'master': master}, '__master_disconnected')

View file

@ -53,22 +53,24 @@ def isportopen(host, port):
return out
def host_to_ip(host):
def host_to_ips(host):
'''
Returns the IP address of a given hostname
Returns a list of IP addresses of a given hostname or None if not found.
'''
ips = []
try:
family, socktype, proto, canonname, sockaddr = socket.getaddrinfo(
host, 0, socket.AF_UNSPEC, socket.SOCK_STREAM)[0]
if family == socket.AF_INET:
ip, port = sockaddr
elif family == socket.AF_INET6:
ip, port, flow_info, scope_id = sockaddr
for family, socktype, proto, canonname, sockaddr in socket.getaddrinfo(
host, 0, socket.AF_UNSPEC, socket.SOCK_STREAM):
if family == socket.AF_INET:
ip, port = sockaddr
elif family == socket.AF_INET6:
ip, port, flow_info, scope_id = sockaddr
ips.append(ip)
if not ips:
ips = None
except Exception:
ip = None
return ip
ips = None
return ips
def _filter_localhost_names(name_list):