2016-05-23 21:11:16 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
Integration tests for the saltutil module.
|
|
|
|
'''
|
|
|
|
|
|
|
|
# Import Python libs
|
2018-01-19 05:49:04 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2017-10-25 19:56:49 +00:00
|
|
|
import os
|
2016-08-22 08:13:16 +00:00
|
|
|
import time
|
2017-10-25 19:56:49 +00:00
|
|
|
import textwrap
|
2016-05-23 21:11:16 +00:00
|
|
|
|
|
|
|
# Import Salt Testing libs
|
2017-04-03 16:04:09 +00:00
|
|
|
from tests.support.case import ModuleCase
|
2017-10-25 19:56:49 +00:00
|
|
|
from tests.support.paths import TMP_PILLAR_TREE
|
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-11-06 03:39:40 +00:00
|
|
|
import salt.utils.files
|
2016-05-23 21:11:16 +00:00
|
|
|
|
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class SaltUtilModuleTest(ModuleCase):
|
2016-05-23 21:11:16 +00:00
|
|
|
'''
|
|
|
|
Testcase for the saltutil execution module
|
|
|
|
'''
|
|
|
|
|
2016-08-22 08:13:16 +00:00
|
|
|
def setUp(self):
|
2016-08-22 10:00:19 +00:00
|
|
|
self.run_function('saltutil.refresh_pillar')
|
2016-08-22 08:13:16 +00:00
|
|
|
|
2016-05-23 21:11:16 +00:00
|
|
|
# Tests for the wheel function
|
|
|
|
|
|
|
|
def test_wheel_just_function(self):
|
|
|
|
'''
|
|
|
|
Tests using the saltutil.wheel function when passing only a function.
|
|
|
|
'''
|
2016-08-22 08:13:16 +00:00
|
|
|
# Wait for the pillar refresh to kick in, so that grains are ready to go
|
2016-08-22 10:00:19 +00:00
|
|
|
time.sleep(3)
|
2016-05-23 21:11:16 +00:00
|
|
|
ret = self.run_function('saltutil.wheel', ['minions.connected'])
|
2016-08-01 16:44:59 +00:00
|
|
|
self.assertIn('minion', ret['return'])
|
|
|
|
self.assertIn('sub_minion', ret['return'])
|
2016-05-23 21:11:16 +00:00
|
|
|
|
|
|
|
def test_wheel_with_arg(self):
|
|
|
|
'''
|
|
|
|
Tests using the saltutil.wheel function when passing a function and an arg.
|
|
|
|
'''
|
|
|
|
ret = self.run_function('saltutil.wheel', ['key.list', 'minion'])
|
2016-08-01 16:44:59 +00:00
|
|
|
self.assertEqual(ret['return'], {})
|
2016-05-23 21:11:16 +00:00
|
|
|
|
|
|
|
def test_wheel_no_arg_raise_error(self):
|
|
|
|
'''
|
|
|
|
Tests using the saltutil.wheel function when passing a function that requires
|
|
|
|
an arg, but one isn't supplied.
|
|
|
|
'''
|
|
|
|
self.assertRaises(TypeError, 'saltutil.wheel', ['key.list'])
|
|
|
|
|
|
|
|
def test_wheel_with_kwarg(self):
|
|
|
|
'''
|
|
|
|
Tests using the saltutil.wheel function when passing a function and a kwarg.
|
|
|
|
This function just generates a key pair, but doesn't do anything with it. We
|
|
|
|
just need this for testing purposes.
|
|
|
|
'''
|
|
|
|
ret = self.run_function('saltutil.wheel', ['key.gen'], keysize=1024)
|
2016-08-01 16:31:09 +00:00
|
|
|
self.assertIn('pub', ret['return'])
|
|
|
|
self.assertIn('priv', ret['return'])
|
2016-05-23 21:11:16 +00:00
|
|
|
|
|
|
|
|
2017-04-03 16:04:09 +00:00
|
|
|
class SaltUtilSyncModuleTest(ModuleCase):
|
2017-02-08 21:39:26 +00:00
|
|
|
'''
|
|
|
|
Testcase for the saltutil sync execution module
|
|
|
|
'''
|
|
|
|
|
|
|
|
def setUp(self):
|
2017-02-09 00:07:13 +00:00
|
|
|
whitelist = {'modules': [], }
|
2017-02-08 21:39:26 +00:00
|
|
|
self.run_function('saltutil.sync_all', extmod_whitelist=whitelist)
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.run_function('saltutil.sync_all')
|
|
|
|
|
|
|
|
def test_sync_all(self):
|
|
|
|
'''
|
|
|
|
Test syncing all ModuleCase
|
|
|
|
'''
|
|
|
|
expected_return = {'engines': [],
|
2017-04-28 15:12:05 +00:00
|
|
|
'clouds': [],
|
2017-02-08 21:39:26 +00:00
|
|
|
'grains': [],
|
|
|
|
'beacons': [],
|
|
|
|
'utils': [],
|
|
|
|
'returners': [],
|
2018-04-02 20:06:50 +00:00
|
|
|
'modules': ['modules.mantest',
|
|
|
|
'modules.override_test',
|
2017-02-08 21:39:26 +00:00
|
|
|
'modules.runtests_decorators',
|
|
|
|
'modules.runtests_helpers',
|
|
|
|
'modules.salttest'],
|
|
|
|
'renderers': [],
|
|
|
|
'log_handlers': [],
|
|
|
|
'states': [],
|
|
|
|
'sdb': [],
|
|
|
|
'proxymodules': [],
|
2017-11-30 15:50:11 +00:00
|
|
|
'output': [],
|
2018-03-08 02:22:34 +00:00
|
|
|
'thorium': [],
|
|
|
|
'serializers': []}
|
2017-02-08 21:39:26 +00:00
|
|
|
ret = self.run_function('saltutil.sync_all')
|
|
|
|
self.assertEqual(ret, expected_return)
|
|
|
|
|
|
|
|
def test_sync_all_whitelist(self):
|
|
|
|
'''
|
2017-02-13 18:19:55 +00:00
|
|
|
Test syncing all ModuleCase with whitelist
|
2017-02-08 21:39:26 +00:00
|
|
|
'''
|
|
|
|
expected_return = {'engines': [],
|
2017-04-28 15:12:05 +00:00
|
|
|
'clouds': [],
|
2017-02-08 21:39:26 +00:00
|
|
|
'grains': [],
|
|
|
|
'beacons': [],
|
|
|
|
'utils': [],
|
|
|
|
'returners': [],
|
|
|
|
'modules': ['modules.salttest'],
|
|
|
|
'renderers': [],
|
|
|
|
'log_handlers': [],
|
|
|
|
'states': [],
|
|
|
|
'sdb': [],
|
|
|
|
'proxymodules': [],
|
2017-11-30 15:50:11 +00:00
|
|
|
'output': [],
|
2018-03-08 02:22:34 +00:00
|
|
|
'thorium': [],
|
|
|
|
'serializers': []}
|
2017-02-08 21:39:26 +00:00
|
|
|
ret = self.run_function('saltutil.sync_all', extmod_whitelist={'modules': ['salttest']})
|
|
|
|
self.assertEqual(ret, expected_return)
|
|
|
|
|
2017-02-13 18:19:55 +00:00
|
|
|
def test_sync_all_blacklist(self):
|
|
|
|
'''
|
|
|
|
Test syncing all ModuleCase with blacklist
|
|
|
|
'''
|
|
|
|
expected_return = {'engines': [],
|
2017-04-28 15:12:05 +00:00
|
|
|
'clouds': [],
|
2017-02-13 18:19:55 +00:00
|
|
|
'grains': [],
|
|
|
|
'beacons': [],
|
|
|
|
'utils': [],
|
|
|
|
'returners': [],
|
2018-04-02 20:06:50 +00:00
|
|
|
'modules': ['modules.mantest',
|
|
|
|
'modules.override_test',
|
2017-02-13 18:19:55 +00:00
|
|
|
'modules.runtests_helpers',
|
|
|
|
'modules.salttest'],
|
|
|
|
'renderers': [],
|
|
|
|
'log_handlers': [],
|
|
|
|
'states': [],
|
|
|
|
'sdb': [],
|
|
|
|
'proxymodules': [],
|
2017-11-30 15:50:11 +00:00
|
|
|
'output': [],
|
2018-03-08 02:22:34 +00:00
|
|
|
'thorium': [],
|
|
|
|
'serializers': []}
|
2017-02-13 18:19:55 +00:00
|
|
|
ret = self.run_function('saltutil.sync_all', extmod_blacklist={'modules': ['runtests_decorators']})
|
|
|
|
self.assertEqual(ret, expected_return)
|
|
|
|
|
|
|
|
def test_sync_all_blacklist_and_whitelist(self):
|
|
|
|
'''
|
|
|
|
Test syncing all ModuleCase with whitelist and blacklist
|
|
|
|
'''
|
|
|
|
expected_return = {'engines': [],
|
2017-04-28 15:12:05 +00:00
|
|
|
'clouds': [],
|
2017-02-13 18:19:55 +00:00
|
|
|
'grains': [],
|
|
|
|
'beacons': [],
|
|
|
|
'utils': [],
|
|
|
|
'returners': [],
|
|
|
|
'modules': [],
|
|
|
|
'renderers': [],
|
|
|
|
'log_handlers': [],
|
|
|
|
'states': [],
|
|
|
|
'sdb': [],
|
|
|
|
'proxymodules': [],
|
2017-11-30 15:50:11 +00:00
|
|
|
'output': [],
|
2018-03-08 02:22:34 +00:00
|
|
|
'thorium': [],
|
|
|
|
'serializers': []}
|
2017-02-13 18:19:55 +00:00
|
|
|
ret = self.run_function('saltutil.sync_all', extmod_whitelist={'modules': ['runtests_decorators']},
|
|
|
|
extmod_blacklist={'modules': ['runtests_decorators']})
|
|
|
|
self.assertEqual(ret, expected_return)
|
2017-10-25 19:56:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SaltUtilSyncPillarTest(ModuleCase):
|
|
|
|
'''
|
|
|
|
Testcase for the saltutil sync pillar module
|
|
|
|
'''
|
|
|
|
|
|
|
|
def test_pillar_refresh(self):
|
|
|
|
'''
|
|
|
|
test pillar refresh module
|
|
|
|
'''
|
|
|
|
pillar_key = 'itworked'
|
|
|
|
|
|
|
|
pre_pillar = self.run_function('pillar.raw')
|
|
|
|
self.assertNotIn(pillar_key, pre_pillar.get(pillar_key, 'didnotwork'))
|
|
|
|
|
2017-11-06 03:39:40 +00:00
|
|
|
with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE, 'add_pillar.sls'), 'w') as fp:
|
2018-01-19 05:49:04 +00:00
|
|
|
fp.write(salt.utils.stringutils.to_str(
|
|
|
|
'{0}: itworked'.format(pillar_key)
|
|
|
|
))
|
2017-10-25 19:56:49 +00:00
|
|
|
|
2017-11-06 03:39:40 +00:00
|
|
|
with salt.utils.files.fopen(os.path.join(TMP_PILLAR_TREE, 'top.sls'), 'w') as fp:
|
2017-10-25 19:56:49 +00:00
|
|
|
fp.write(textwrap.dedent('''\
|
|
|
|
base:
|
|
|
|
'*':
|
|
|
|
- add_pillar
|
|
|
|
'''))
|
|
|
|
|
2017-11-06 03:39:40 +00:00
|
|
|
self.run_function('saltutil.refresh_pillar')
|
2018-05-25 19:13:56 +00:00
|
|
|
|
|
|
|
pillar = False
|
|
|
|
timeout = time.time() + 30
|
|
|
|
while not pillar:
|
|
|
|
post_pillar = self.run_function('pillar.raw')
|
|
|
|
try:
|
|
|
|
self.assertIn(pillar_key, post_pillar.get(pillar_key, 'didnotwork'))
|
|
|
|
pillar = True
|
|
|
|
except AssertionError:
|
|
|
|
if time.time() > timeout:
|
|
|
|
self.assertIn(pillar_key, post_pillar.get(pillar_key, 'didnotwork'))
|
|
|
|
continue
|
2017-10-25 19:56:49 +00:00
|
|
|
|
|
|
|
post_pillar = self.run_function('pillar.raw')
|
|
|
|
self.assertIn(pillar_key, post_pillar.get(pillar_key, 'didnotwork'))
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
for filename in os.listdir(TMP_PILLAR_TREE):
|
|
|
|
os.remove(os.path.join(TMP_PILLAR_TREE, filename))
|