mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #45676 from terminalmage/ubuntu14-test-fixes
Ubuntu 14 test fixes
This commit is contained in:
commit
16e4b5b57d
@ -2427,27 +2427,29 @@ def default_gateway():
|
||||
ip_gw: True # True if either of the above is True, False otherwise
|
||||
'''
|
||||
grains = {}
|
||||
if not salt.utils.path.which('ip'):
|
||||
ip_bin = salt.utils.path.which('ip')
|
||||
if not ip_bin:
|
||||
return {}
|
||||
grains['ip_gw'] = False
|
||||
grains['ip4_gw'] = False
|
||||
grains['ip6_gw'] = False
|
||||
if __salt__['cmd.run']('ip -4 route show | grep "^default"', python_shell=True):
|
||||
grains['ip_gw'] = True
|
||||
grains['ip4_gw'] = True
|
||||
for ip_version in ('4', '6'):
|
||||
try:
|
||||
gateway_ip = __salt__['cmd.run']('ip -4 route show | grep "^default via"', python_shell=True).split(' ')[2].strip()
|
||||
grains['ip4_gw'] = gateway_ip if gateway_ip else True
|
||||
except Exception as exc:
|
||||
pass
|
||||
if __salt__['cmd.run']('ip -6 route show | grep "^default"', python_shell=True):
|
||||
grains['ip_gw'] = True
|
||||
grains['ip6_gw'] = True
|
||||
try:
|
||||
gateway_ip = __salt__['cmd.run']('ip -6 route show | grep "^default via"', python_shell=True).split(' ')[2].strip()
|
||||
grains['ip6_gw'] = gateway_ip if gateway_ip else True
|
||||
except Exception as exc:
|
||||
pass
|
||||
out = __salt__['cmd.run']([ip_bin, '-' + ip_version, 'route', 'show'])
|
||||
for line in out.splitlines():
|
||||
if line.startswith('default'):
|
||||
grains['ip_gw'] = True
|
||||
grains['ip{0}_gw'.format(ip_version)] = True
|
||||
try:
|
||||
via, gw_ip = line.split()[1:3]
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
if via == 'via':
|
||||
grains['ip{0}_gw'.format(ip_version)] = gw_ip
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
return grains
|
||||
|
||||
|
||||
|
@ -13,7 +13,7 @@ from tests.support.unit import TestCase, skipIf
|
||||
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch, MagicMock
|
||||
from tests.support.helpers import skip_if_not_root
|
||||
# Import salt libs
|
||||
import salt.minion as minion
|
||||
import salt.minion
|
||||
import salt.utils.event as event
|
||||
from salt.exceptions import SaltSystemExit
|
||||
import salt.syspaths
|
||||
@ -27,7 +27,7 @@ __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__)
|
||||
self.assertRaises(SaltSystemExit, salt.minion.resolve_dns, __opts__)
|
||||
|
||||
@skip_if_not_root
|
||||
def test_sock_path_len(self):
|
||||
@ -68,8 +68,8 @@ class MinionTestCase(TestCase):
|
||||
mock_data = {'fun': 'foo.bar',
|
||||
'jid': 123}
|
||||
mock_jid_queue = [123]
|
||||
minion = salt.minion.Minion(mock_opts, jid_queue=copy.copy(mock_jid_queue), io_loop=tornado.ioloop.IOLoop())
|
||||
try:
|
||||
minion = salt.minion.Minion(mock_opts, jid_queue=copy.copy(mock_jid_queue), io_loop=tornado.ioloop.IOLoop())
|
||||
ret = minion._handle_decoded_payload(mock_data).result()
|
||||
self.assertEqual(minion.jid_queue, mock_jid_queue)
|
||||
self.assertIsNone(ret)
|
||||
@ -89,8 +89,8 @@ class MinionTestCase(TestCase):
|
||||
mock_data = {'fun': 'foo.bar',
|
||||
'jid': mock_jid}
|
||||
mock_jid_queue = [123, 456]
|
||||
minion = salt.minion.Minion(mock_opts, jid_queue=copy.copy(mock_jid_queue), io_loop=tornado.ioloop.IOLoop())
|
||||
try:
|
||||
minion = salt.minion.Minion(mock_opts, jid_queue=copy.copy(mock_jid_queue), io_loop=tornado.ioloop.IOLoop())
|
||||
|
||||
# Assert that the minion's jid_queue attribute matches the mock_jid_queue as a baseline
|
||||
# This can help debug any test failures if the _handle_decoded_payload call fails.
|
||||
@ -118,8 +118,8 @@ class MinionTestCase(TestCase):
|
||||
mock_data = {'fun': 'foo.bar',
|
||||
'jid': 789}
|
||||
mock_jid_queue = [123, 456]
|
||||
minion = salt.minion.Minion(mock_opts, jid_queue=copy.copy(mock_jid_queue), io_loop=tornado.ioloop.IOLoop())
|
||||
try:
|
||||
minion = salt.minion.Minion(mock_opts, jid_queue=copy.copy(mock_jid_queue), io_loop=tornado.ioloop.IOLoop())
|
||||
|
||||
# Assert that the minion's jid_queue attribute matches the mock_jid_queue as a baseline
|
||||
# This can help debug any test failures if the _handle_decoded_payload call fails.
|
||||
@ -148,9 +148,9 @@ class MinionTestCase(TestCase):
|
||||
mock_opts['minion_jid_queue_hwm'] = 100
|
||||
mock_opts["process_count_max"] = process_count_max
|
||||
|
||||
io_loop = tornado.ioloop.IOLoop()
|
||||
minion = salt.minion.Minion(mock_opts, jid_queue=[], io_loop=io_loop)
|
||||
try:
|
||||
io_loop = tornado.ioloop.IOLoop()
|
||||
minion = salt.minion.Minion(mock_opts, jid_queue=[], io_loop=io_loop)
|
||||
|
||||
# mock gen.sleep to throw a special Exception when called, so that we detect it
|
||||
class SleepCalledEception(Exception):
|
||||
@ -189,8 +189,8 @@ class MinionTestCase(TestCase):
|
||||
patch('salt.utils.process.SignalHandlingMultiprocessingProcess.join', MagicMock(return_value=True)):
|
||||
mock_opts = copy.copy(salt.config.DEFAULT_MINION_OPTS)
|
||||
mock_opts['beacons_before_connect'] = True
|
||||
minion = salt.minion.Minion(mock_opts, io_loop=tornado.ioloop.IOLoop())
|
||||
try:
|
||||
minion = salt.minion.Minion(mock_opts, io_loop=tornado.ioloop.IOLoop())
|
||||
|
||||
try:
|
||||
minion.tune_in(start=True)
|
||||
@ -213,9 +213,8 @@ class MinionTestCase(TestCase):
|
||||
patch('salt.utils.process.SignalHandlingMultiprocessingProcess.join', MagicMock(return_value=True)):
|
||||
mock_opts = copy.copy(salt.config.DEFAULT_MINION_OPTS)
|
||||
mock_opts['scheduler_before_connect'] = True
|
||||
minion = salt.minion.Minion(mock_opts, io_loop=tornado.ioloop.IOLoop())
|
||||
try:
|
||||
minion = salt.minion.Minion(mock_opts, io_loop=tornado.ioloop.IOLoop())
|
||||
|
||||
try:
|
||||
minion.tune_in(start=True)
|
||||
except RuntimeError:
|
||||
|
Loading…
Reference in New Issue
Block a user