mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge branch '2018.3' into 2018.3
This commit is contained in:
commit
501c8dff9c
2 changed files with 26 additions and 1 deletions
|
@ -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,
|
||||
|
|
|
@ -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'))
|
||||
|
|
Loading…
Add table
Reference in a new issue