mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Allow getting the configuration from scratch.
Properly handle `client_config` when loading from cache. Only delete the `_client` attribute if it has been set.
This commit is contained in:
parent
cb5651e79b
commit
b32d86d0f4
6 changed files with 42 additions and 30 deletions
|
@ -556,11 +556,13 @@ class TestDaemon(object):
|
|||
os.path.join(master_opts['pki_dir'], 'minions_rejected'),
|
||||
os.path.join(master_opts['cachedir'], 'jobs'),
|
||||
os.path.join(master_opts['cachedir'], 'raet'),
|
||||
os.path.join(master_opts['root_dir'], 'cache', 'tokens'),
|
||||
os.path.join(syndic_master_opts['pki_dir'], 'minions'),
|
||||
os.path.join(syndic_master_opts['pki_dir'], 'minions_pre'),
|
||||
os.path.join(syndic_master_opts['pki_dir'], 'minions_rejected'),
|
||||
os.path.join(syndic_master_opts['cachedir'], 'jobs'),
|
||||
os.path.join(syndic_master_opts['cachedir'], 'raet'),
|
||||
os.path.join(syndic_master_opts['root_dir'], 'cache', 'tokens'),
|
||||
os.path.join(master_opts['pki_dir'], 'accepted'),
|
||||
os.path.join(master_opts['pki_dir'], 'rejected'),
|
||||
os.path.join(master_opts['pki_dir'], 'pending'),
|
||||
|
@ -924,7 +926,20 @@ class AdaptedConfigurationTestCaseMixIn(object):
|
|||
|
||||
__slots__ = ()
|
||||
|
||||
def get_config(self, config_for):
|
||||
def get_config(self, config_for, from_scratch=False):
|
||||
if from_scratch:
|
||||
if config_for in ('master', 'syndic_master'):
|
||||
return salt.config.master_config(self.get_config_file_path(config_for))
|
||||
elif config_for in ('minion', 'sub_minion'):
|
||||
return salt.config.minion_config(self.get_config_file_path(config_for))
|
||||
elif config_for in ('syndic',):
|
||||
return salt.config.syndic_config(
|
||||
self.get_config_file_path(config_for),
|
||||
self.get_config_file_path('minion')
|
||||
)
|
||||
elif config_for == 'client_config':
|
||||
return salt.config.client_config(self.get_config_file_path('master'))
|
||||
|
||||
if config_for not in RUNTIME_CONFIGS:
|
||||
if config_for in ('master', 'syndic_master'):
|
||||
RUNTIME_CONFIGS[config_for] = freeze(
|
||||
|
@ -941,6 +956,10 @@ class AdaptedConfigurationTestCaseMixIn(object):
|
|||
self.get_config_file_path('minion')
|
||||
)
|
||||
)
|
||||
elif config_for == 'client_config':
|
||||
RUNTIME_CONFIGS[config_for] = freeze(
|
||||
salt.config.client_config(self.get_config_file_path('master'))
|
||||
)
|
||||
return RUNTIME_CONFIGS[config_for]
|
||||
|
||||
def get_config_dir(self):
|
||||
|
@ -971,8 +990,9 @@ class SaltClientTestCaseMixIn(AdaptedConfigurationTestCaseMixIn):
|
|||
return self._client
|
||||
|
||||
def __del__(self):
|
||||
del self._client
|
||||
self._client = None
|
||||
if hasattr(self, '_client'):
|
||||
del self._client
|
||||
self._client = None
|
||||
|
||||
|
||||
class ModuleCase(TestCase, SaltClientTestCaseMixIn):
|
||||
|
@ -1408,13 +1428,6 @@ class ClientCase(AdaptedConfigurationTestCaseMixIn, TestCase):
|
|||
A base class containing relevant options for starting the various Salt
|
||||
Python API entrypoints
|
||||
'''
|
||||
def get_opts(self):
|
||||
if 'client_config' not in RUNTIME_CONFIGS:
|
||||
RUNTIME_CONFIGS = freeze(
|
||||
salt.config.client_config(self.get_config_file_path('master'))
|
||||
)
|
||||
return RUNTIME_CONFIGS['client_config']
|
||||
|
||||
def mkdir_p(self, path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
|
|
|
@ -35,7 +35,7 @@ class FileClientTest(integration.ModuleCase):
|
|||
self.file_client.get_file(None)
|
||||
|
||||
def test_get_file_client(self):
|
||||
with patch.dict(self.minion_opts, {'file_client': 'remote'}):
|
||||
with patch.dict(self.get_config('minion', from_scratch=True), {'file_client': 'remote'}):
|
||||
with patch('salt.fileclient.RemoteClient', MagicMock(return_value='remote_client')):
|
||||
ret = fileclient.get_file_client(self.minion_opts)
|
||||
self.assertEqual('remote_client', ret)
|
||||
|
|
|
@ -158,9 +158,6 @@ class RootsTest(integration.ModuleCase):
|
|||
|
||||
class RootsLimitTraversalTest(integration.ModuleCase):
|
||||
|
||||
def setUp(self):
|
||||
self.master_opts['file_roots']['base'] = [os.path.join(integration.FILES, 'file', 'base')]
|
||||
|
||||
# @destructiveTest
|
||||
def test_limit_traversal(self):
|
||||
'''
|
||||
|
@ -169,7 +166,7 @@ class RootsLimitTraversalTest(integration.ModuleCase):
|
|||
3) Ensure that we can find SLS files in a directory so long as there is an SLS file in a directory above.
|
||||
4) Ensure that we cannot find an SLS file in a directory that does not have an SLS file in a directory above.
|
||||
'''
|
||||
file_client_opts = self.master_opts
|
||||
file_client_opts = self.get_config('master', from_scratch=True)
|
||||
file_client_opts['fileserver_limit_traversal'] = True
|
||||
|
||||
ret = fileclient.Client(file_client_opts).list_states('base')
|
||||
|
|
|
@ -10,7 +10,7 @@ import integration
|
|||
import salt.runner
|
||||
|
||||
|
||||
class RunnerModuleTest(integration.ClientCase):
|
||||
class RunnerModuleTest(integration.TestCase, integration.AdaptedConfigurationTestCaseMixIn):
|
||||
eauth_creds = {
|
||||
'username': 'saltdev_auto',
|
||||
'password': 'saltdev',
|
||||
|
@ -21,7 +21,7 @@ class RunnerModuleTest(integration.ClientCase):
|
|||
'''
|
||||
Configure an eauth user to test with
|
||||
'''
|
||||
self.runner = salt.runner.RunnerClient(self.get_opts())
|
||||
self.runner = salt.runner.RunnerClient(self.get_config('client_config'))
|
||||
|
||||
def test_eauth(self):
|
||||
'''
|
||||
|
@ -47,10 +47,7 @@ class RunnerModuleTest(integration.ClientCase):
|
|||
'''
|
||||
import salt.auth
|
||||
|
||||
opts = self.get_opts()
|
||||
self.mkdir_p(os.path.join(opts['root_dir'], 'cache', 'tokens'))
|
||||
|
||||
auth = salt.auth.LoadAuth(opts)
|
||||
auth = salt.auth.LoadAuth(self.get_config('client_config'))
|
||||
token = auth.mk_token(self.eauth_creds)
|
||||
|
||||
self.runner.master_call(**{
|
||||
|
@ -100,6 +97,7 @@ class RunnerModuleTest(integration.ClientCase):
|
|||
}
|
||||
self.runner.cmd_sync(low)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(RunnerModuleTest, needs_daemon=True)
|
||||
|
|
|
@ -7,10 +7,12 @@ import os
|
|||
import integration
|
||||
|
||||
# Import Salt libs
|
||||
import salt.auth
|
||||
import salt.wheel
|
||||
|
||||
|
||||
class WheelModuleTest(integration.ClientCase):
|
||||
class WheelModuleTest(integration.TestCase, integration.AdaptedConfigurationTestCaseMixIn):
|
||||
|
||||
eauth_creds = {
|
||||
'username': 'saltdev_auto',
|
||||
'password': 'saltdev',
|
||||
|
@ -21,7 +23,7 @@ class WheelModuleTest(integration.ClientCase):
|
|||
'''
|
||||
Configure an eauth user to test with
|
||||
'''
|
||||
self.wheel = salt.wheel.Wheel(self.get_opts())
|
||||
self.wheel = salt.wheel.Wheel(self.get_config('client_config'))
|
||||
|
||||
def test_master_call(self):
|
||||
'''
|
||||
|
@ -45,14 +47,15 @@ class WheelModuleTest(integration.ClientCase):
|
|||
The choice of using key.list_all for this is arbitrary and should be
|
||||
changed to some mocked function that is more testing friendly.
|
||||
'''
|
||||
import salt.auth
|
||||
|
||||
opts = self.get_opts()
|
||||
self.mkdir_p(os.path.join(opts['root_dir'], 'cache', 'tokens'))
|
||||
|
||||
auth = salt.auth.LoadAuth(opts)
|
||||
auth = salt.auth.LoadAuth(self.get_config('client_config'))
|
||||
token = auth.mk_token(self.eauth_creds)
|
||||
|
||||
token = auth.mk_token({
|
||||
'username': 'saltdev_auto',
|
||||
'password': 'saltdev',
|
||||
'eauth': 'auto',
|
||||
})
|
||||
|
||||
self.wheel.master_call(**{
|
||||
'client': 'wheel',
|
||||
'fun': 'key.list_all',
|
||||
|
@ -97,6 +100,7 @@ class WheelModuleTest(integration.ClientCase):
|
|||
|
||||
self.wheel.cmd_sync(low)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(WheelModuleTest, needs_daemon=True)
|
||||
|
|
|
@ -9,7 +9,7 @@ import salt.wheel
|
|||
|
||||
class KeyWheelModuleTest(integration.ClientCase):
|
||||
def setUp(self):
|
||||
self.wheel = salt.wheel.Wheel(self.get_opts())
|
||||
self.wheel = salt.wheel.Wheel(self.get_config('client_config'))
|
||||
|
||||
def test_list_all(self):
|
||||
ret = self.wheel.call_func('key.list_all')
|
||||
|
|
Loading…
Add table
Reference in a new issue