mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge branch '2018.3' into 1257_something_something_bytes_argh_python2
This commit is contained in:
commit
bd7072f3c8
@ -806,7 +806,7 @@ def default_signals(*signals):
|
||||
old_signals = {}
|
||||
for signum in signals:
|
||||
try:
|
||||
old_signals[signum] = signal.getsignal(signum)
|
||||
saved_signal = signal.getsignal(signum)
|
||||
signal.signal(signum, signal.SIG_DFL)
|
||||
except ValueError as exc:
|
||||
# This happens when a netapi module attempts to run a function
|
||||
@ -816,6 +816,8 @@ def default_signals(*signals):
|
||||
'Failed to register signal for signum %d: %s',
|
||||
signum, exc
|
||||
)
|
||||
else:
|
||||
old_signals[signum] = saved_signal
|
||||
|
||||
# Do whatever is needed with the reset signals
|
||||
yield
|
||||
|
@ -232,6 +232,54 @@ class NetworkTestCase(TestCase):
|
||||
log.error('bad host_port value: "%s" failed to trigger ValueError exception', host_port)
|
||||
raise _e_
|
||||
|
||||
def test_dns_check(self):
|
||||
class MockSocket(object):
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def setsockopt(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def sendto(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def connect(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def close(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
hosts = [
|
||||
{'host': '10.10.0.3',
|
||||
'port': '',
|
||||
'mocked': [(2, 1, 6, '', ('10.10.0.3', 0))],
|
||||
'ret': '10.10.0.3'},
|
||||
{'host': '10.10.0.3',
|
||||
'port': '1234',
|
||||
'mocked': [(2, 1, 6, '', ('10.10.0.3', 0))],
|
||||
'ret': '10.10.0.3'},
|
||||
{'host': '2001:0db8:85a3::8a2e:0370:7334',
|
||||
'port': '',
|
||||
'mocked': [(10, 1, 6, '', ('2001:db8:85a3::8a2e:370:7334', 0, 0, 0))],
|
||||
'ret': '2001:db8:85a3::8a2e:370:7334'},
|
||||
{'host': '2001:0db8:85a3::8a2e:370:7334',
|
||||
'port': '1234',
|
||||
'mocked': [(10, 1, 6, '', ('2001:db8:85a3::8a2e:370:7334', 0, 0, 0))],
|
||||
'ret': '2001:db8:85a3::8a2e:370:7334'},
|
||||
{'host': 'salt-master',
|
||||
'port': '1234',
|
||||
'mocked': [(2, 1, 6, '', ('127.0.0.1', 0))],
|
||||
'ret': '127.0.0.1'},
|
||||
]
|
||||
for host in hosts:
|
||||
with patch.object(socket, 'getaddrinfo', MagicMock(return_value=host['mocked'])):
|
||||
with patch('socket.socket', MockSocket):
|
||||
ret = network.dns_check(host['host'], host['port'])
|
||||
self.assertEqual(ret, host['ret'])
|
||||
|
||||
def test_is_subnet(self):
|
||||
for subnet_data in (IPV4_SUBNETS, IPV6_SUBNETS):
|
||||
for item in subnet_data[True]:
|
||||
|
Loading…
Reference in New Issue
Block a user