Merge branch '2018.3' into 2018.3

This commit is contained in:
jpsv 2019-01-14 18:51:01 -05:00 committed by GitHub
commit 501c8dff9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -137,7 +137,23 @@ def _generate_minion_id():
def first(self):
return self and self[0] or None
hosts = DistinctList().append(socket.getfqdn()).append(platform.node()).append(socket.gethostname())
hosts = DistinctList([])
try:
hosts.append(socket.getfqdn())
except ValueError:
pass
try:
hosts.append(platform.node())
except ValueError:
pass
try:
hosts.append(socket.gethostname())
except ValueError:
pass
if not hosts:
try:
for a_nfo in socket.getaddrinfo(hosts.first() or 'localhost', None, socket.AF_INET,

View file

@ -181,6 +181,15 @@ class NetworkTestCase(TestCase):
with patch('salt.utils.files.fopen', fopen_mock):
assert 'thisismyhostname' in network._generate_minion_id()
def test_generate_minion_id_with_long_hostname(self):
'''
Test that hostnames longer than 63 characters do not raise
an exception when generating the minion ID
'''
with patch('socket.gethostbyaddr') as mock_gethostbyname:
mock_gethostbyname.side_effect = UnicodeError('encoding with \'idna\' codec failed')
self.assertTrue(network.generate_minion_id())
def test_is_ip(self):
self.assertTrue(network.is_ip('10.10.0.3'))
self.assertFalse(network.is_ip('0.9.800.1000'))