mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Handle invalid master address in minion config
Gracefully exit the minion while informing the user of the cause of the error if the IP address of the master is malformed such that it can not even be dealt with by Python's socket module. Unit testing for the above condition. Closes #9440. Remove suprious debugging statement. Remove more spurious debugging.
This commit is contained in:
parent
f54736aab6
commit
f2f7e9f537
@ -53,7 +53,7 @@ except ImportError:
|
||||
# Import salt libs
|
||||
from salt.exceptions import (
|
||||
AuthenticationError, CommandExecutionError, CommandNotFoundError,
|
||||
SaltInvocationError, SaltReqTimeoutError, SaltClientError
|
||||
SaltInvocationError, SaltReqTimeoutError, SaltClientError, SaltSystemExit
|
||||
)
|
||||
import salt.client
|
||||
import salt.crypt
|
||||
@ -112,6 +112,11 @@ def resolve_dns(opts):
|
||||
pass
|
||||
else:
|
||||
ret['master_ip'] = '127.0.0.1'
|
||||
except SaltSystemExit:
|
||||
err = 'Master address: {0} could not be resolved. Invalid or unresolveable address.'.format(
|
||||
opts.get('master', 'Unknown'))
|
||||
log.error(err)
|
||||
raise SaltSystemExit(code=42, msg=err)
|
||||
else:
|
||||
ret['master_ip'] = '127.0.0.1'
|
||||
|
||||
|
@ -481,6 +481,9 @@ def dns_check(addr, safe=False, ipv6=False):
|
||||
break
|
||||
if not addr:
|
||||
error = True
|
||||
except TypeError:
|
||||
err = ('Attempt to resolve address failed. Invalid or unresolveable address')
|
||||
raise SaltSystemExit(code=42, msg=err)
|
||||
except socket.error:
|
||||
error = True
|
||||
|
||||
|
23
tests/unit/minion_test.py
Normal file
23
tests/unit/minion_test.py
Normal file
@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codauthor: :email:`Mike Place <mp@saltstack.com>`
|
||||
'''
|
||||
|
||||
# Import Salt Testing libs
|
||||
from salttesting import TestCase
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
from salttesting.mock import patch
|
||||
|
||||
from salt import minion
|
||||
from salt.exceptions import SaltSystemExit
|
||||
|
||||
|
||||
ensure_in_syspath('../')
|
||||
|
||||
__opts__ = {}
|
||||
|
||||
|
||||
class MinionTestCase(TestCase):
|
||||
def test_invalid_master_address(self):
|
||||
with patch.dict(__opts__, {'ipv6': False, 'master': float('127.0'), 'master_port': '4555', 'retry_dns': False}):
|
||||
self.assertRaises(SaltSystemExit, minion.resolve_dns, __opts__)
|
Loading…
Reference in New Issue
Block a user