Merge branch '2018.3' into 1257_something_something_bytes_argh_python2

This commit is contained in:
Pedro Algarvio 2019-01-25 09:34:49 +00:00 committed by GitHub
commit bd7072f3c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 1 deletions

View File

@ -806,7 +806,7 @@ def default_signals(*signals):
old_signals = {} old_signals = {}
for signum in signals: for signum in signals:
try: try:
old_signals[signum] = signal.getsignal(signum) saved_signal = signal.getsignal(signum)
signal.signal(signum, signal.SIG_DFL) signal.signal(signum, signal.SIG_DFL)
except ValueError as exc: except ValueError as exc:
# This happens when a netapi module attempts to run a function # 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', 'Failed to register signal for signum %d: %s',
signum, exc signum, exc
) )
else:
old_signals[signum] = saved_signal
# Do whatever is needed with the reset signals # Do whatever is needed with the reset signals
yield yield

View File

@ -232,6 +232,54 @@ class NetworkTestCase(TestCase):
log.error('bad host_port value: "%s" failed to trigger ValueError exception', host_port) log.error('bad host_port value: "%s" failed to trigger ValueError exception', host_port)
raise _e_ 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): def test_is_subnet(self):
for subnet_data in (IPV4_SUBNETS, IPV6_SUBNETS): for subnet_data in (IPV4_SUBNETS, IPV6_SUBNETS):
for item in subnet_data[True]: for item in subnet_data[True]: