Add for new source_* minion options

This commit is contained in:
Ch3LL 2018-03-13 16:27:02 -04:00
parent c6431936cb
commit e972ebdf1a
No known key found for this signature in database
GPG Key ID: 132B55A7C13EFA73
3 changed files with 105 additions and 2 deletions

View File

@ -144,10 +144,10 @@ def resolve_dns(opts, fallback=True):
if (opts.get('file_client', 'remote') == 'local' and
not opts.get('use_master_when_local', False)):
check_dns = False
# Because I import salt.log below I need to re-import salt.utils here
import salt.utils
if check_dns is True:
# Because I import salt.log below I need to re-import salt.utils here
import salt.utils
try:
if opts['master'] == '':
raise SaltSystemExit

View File

@ -29,6 +29,78 @@ class MinionTestCase(TestCase):
with patch.dict(__opts__, {'ipv6': False, 'master': float('127.0'), 'master_port': '4555', 'retry_dns': False}):
self.assertRaises(SaltSystemExit, salt.minion.resolve_dns, __opts__)
def test_source_int_name_local(self):
'''
test when file_client local and
source_interface_name is set
'''
interfaces = {'bond0.1234': {'hwaddr': '01:01:01:d0:d0:d0',
'up': True, 'inet':
[{'broadcast': '111.1.111.255',
'netmask': '111.1.0.0',
'label': 'bond0',
'address': '111.1.0.1'}]}}
with patch.dict(__opts__, {'ipv6': False, 'master': '127.0.0.1',
'master_port': '4555', 'file_client': 'local',
'source_interface_name': 'bond0.1234',
'source_ret_port': 49017,
'source_publish_port': 49018}), \
patch('salt.utils.network.interfaces',
MagicMock(return_value=interfaces)):
assert salt.minion.resolve_dns(__opts__) == {'master_ip': '127.0.0.1',
'source_ip': '111.1.0.1',
'source_ret_port': 49017,
'source_publish_port': 49018,
'master_uri': 'tcp://127.0.0.1:4555'}
def test_source_int_name_remote(self):
'''
test when file_client remote and
source_interface_name is set and
interface is down
'''
interfaces = {'bond0.1234': {'hwaddr': '01:01:01:d0:d0:d0',
'up': False, 'inet':
[{'broadcast': '111.1.111.255',
'netmask': '111.1.0.0',
'label': 'bond0',
'address': '111.1.0.1'}]}}
with patch.dict(__opts__, {'ipv6': False, 'master': '127.0.0.1',
'master_port': '4555', 'file_client': 'remote',
'source_interface_name': 'bond0.1234',
'source_ret_port': 49017,
'source_publish_port': 49018}), \
patch('salt.utils.network.interfaces',
MagicMock(return_value=interfaces)):
assert salt.minion.resolve_dns(__opts__) == {'master_ip': '127.0.0.1',
'source_ret_port': 49017,
'source_publish_port': 49018,
'master_uri': 'tcp://127.0.0.1:4555'}
def test_source_address(self):
'''
test when source_address is set
'''
interfaces = {'bond0.1234': {'hwaddr': '01:01:01:d0:d0:d0',
'up': False, 'inet':
[{'broadcast': '111.1.111.255',
'netmask': '111.1.0.0',
'label': 'bond0',
'address': '111.1.0.1'}]}}
with patch.dict(__opts__, {'ipv6': False, 'master': '127.0.0.1',
'master_port': '4555', 'file_client': 'local',
'source_interface_name': '',
'source_address': '111.1.0.1',
'source_ret_port': 49017,
'source_publish_port': 49018}), \
patch('salt.utils.network.interfaces',
MagicMock(return_value=interfaces)):
assert salt.minion.resolve_dns(__opts__) == {'source_publish_port': 49018,
'source_ret_port': 49017,
'master_uri': 'tcp://127.0.0.1:4555',
'source_ip': '111.1.0.1',
'master_ip': '127.0.0.1'}
@skip_if_not_root
def test_sock_path_len(self):
'''

View File

@ -305,3 +305,34 @@ class AsyncReqMessageClientPoolTest(TestCase):
def test_destroy(self):
self.message_client_pool.destroy()
self.assertEqual([], self.message_client_pool.message_clients)
class ZMQConfigTest(TestCase):
def test_master_uri(self):
'''
test _get_master_uri method
'''
m_ip = '127.0.0.1'
m_port = 4505
s_ip = '111.1.0.1'
s_port = 4058
# source ip and source_port empty
assert salt.transport.zeromq._get_master_uri(master_ip=m_ip,
master_port=m_port) == 'tcp://{0}:{1}'.format(m_ip, m_port)
# pass in both source_ip and source_port
assert salt.transport.zeromq._get_master_uri(master_ip=m_ip,
master_port=m_port,
source_ip=s_ip,
source_port=s_port) == 'tcp://{0}:{1};{2}:{3}'.format(s_ip, s_port, m_ip, m_port)
# pass in only source_ip
assert salt.transport.zeromq._get_master_uri(master_ip=m_ip,
master_port=m_port,
source_ip=s_ip) == 'tcp://{0}:0;{1}:{2}'.format(s_ip, m_ip, m_port)
# pass in only source_port
assert salt.transport.zeromq._get_master_uri(master_ip=m_ip,
master_port=m_port,
source_port=s_port) == 'tcp://0.0.0.0:{0};{1}:{2}'.format(s_port, m_ip, m_port)