mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Merge pull request #47066 from terminalmage/issue46979
Fix regression in handling of environment/saltenv
This commit is contained in:
commit
fa27e64a33
@ -3675,6 +3675,8 @@ def apply_minion_config(overrides=None,
|
||||
'''
|
||||
if defaults is None:
|
||||
defaults = DEFAULT_MINION_OPTS
|
||||
if overrides is None:
|
||||
overrides = {}
|
||||
|
||||
opts = defaults.copy()
|
||||
opts['__role'] = 'minion'
|
||||
@ -3683,7 +3685,7 @@ def apply_minion_config(overrides=None,
|
||||
opts.update(overrides)
|
||||
|
||||
if 'environment' in opts:
|
||||
if 'saltenv' in opts:
|
||||
if opts['saltenv'] is not None:
|
||||
log.warning(
|
||||
'The \'saltenv\' and \'environment\' minion config options '
|
||||
'cannot both be used. Ignoring \'environment\' in favor of '
|
||||
@ -3783,7 +3785,7 @@ def apply_minion_config(overrides=None,
|
||||
if 'beacons' not in opts:
|
||||
opts['beacons'] = {}
|
||||
|
||||
if (overrides or {}).get('ipc_write_buffer', '') == 'dynamic':
|
||||
if overrides.get('ipc_write_buffer', '') == 'dynamic':
|
||||
opts['ipc_write_buffer'] = _DFLT_IPC_WBUFFER
|
||||
if 'ipc_write_buffer' not in overrides:
|
||||
opts['ipc_write_buffer'] = 0
|
||||
@ -3872,6 +3874,8 @@ def apply_master_config(overrides=None, defaults=None):
|
||||
'''
|
||||
if defaults is None:
|
||||
defaults = DEFAULT_MASTER_OPTS
|
||||
if overrides is None:
|
||||
overrides = {}
|
||||
|
||||
opts = defaults.copy()
|
||||
opts['__role'] = 'master'
|
||||
@ -3880,7 +3884,7 @@ def apply_master_config(overrides=None, defaults=None):
|
||||
opts.update(overrides)
|
||||
|
||||
if 'environment' in opts:
|
||||
if 'saltenv' in opts:
|
||||
if opts['saltenv'] is not None:
|
||||
log.warning(
|
||||
'The \'saltenv\' and \'environment\' master config options '
|
||||
'cannot both be used. Ignoring \'environment\' in favor of '
|
||||
@ -3930,7 +3934,7 @@ def apply_master_config(overrides=None, defaults=None):
|
||||
# Insert all 'utils_dirs' directories to the system path
|
||||
insert_system_path(opts, opts['utils_dirs'])
|
||||
|
||||
if (overrides or {}).get('ipc_write_buffer', '') == 'dynamic':
|
||||
if overrides.get('ipc_write_buffer', '') == 'dynamic':
|
||||
opts['ipc_write_buffer'] = _DFLT_IPC_WBUFFER
|
||||
if 'ipc_write_buffer' not in overrides:
|
||||
opts['ipc_write_buffer'] = 0
|
||||
|
@ -19,7 +19,7 @@ import textwrap
|
||||
from tests.support.mixins import AdaptedConfigurationTestCaseMixin
|
||||
from tests.support.paths import TMP
|
||||
from tests.support.unit import skipIf, TestCase
|
||||
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch
|
||||
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, Mock, MagicMock, patch
|
||||
|
||||
# Import Salt libs
|
||||
import salt.minion
|
||||
@ -1318,3 +1318,92 @@ class ConfigTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
|
||||
config_path,
|
||||
verbose=False,
|
||||
exit_on_config_errors=True)
|
||||
|
||||
@staticmethod
|
||||
def _get_defaults(**kwargs):
|
||||
ret = {
|
||||
'saltenv': kwargs.pop('saltenv', None),
|
||||
'id': 'test',
|
||||
'cachedir': '/A',
|
||||
'sock_dir': '/B',
|
||||
'root_dir': '/C',
|
||||
'fileserver_backend': 'roots',
|
||||
'open_mode': False,
|
||||
'auto_accept': False,
|
||||
'file_roots': {},
|
||||
'pillar_roots': {},
|
||||
'file_ignore_glob': [],
|
||||
'file_ignore_regex': [],
|
||||
'worker_threads': 5,
|
||||
'hash_type': 'sha256',
|
||||
'log_file': 'foo.log',
|
||||
}
|
||||
ret.update(kwargs)
|
||||
return ret
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
def test_apply_config(self):
|
||||
'''
|
||||
Ensure that the environment and saltenv options work properly
|
||||
'''
|
||||
with patch.object(sconfig, '_adjust_log_file_override', Mock()), \
|
||||
patch.object(sconfig, '_update_ssl_config', Mock()), \
|
||||
patch.object(sconfig, '_update_discovery_config', Mock()):
|
||||
|
||||
# MASTER CONFIG
|
||||
|
||||
# Ensure that environment overrides saltenv when saltenv not
|
||||
# explicitly passed.
|
||||
defaults = self._get_defaults(environment='foo')
|
||||
ret = sconfig.apply_master_config(defaults=defaults)
|
||||
self.assertEqual(ret['environment'], 'foo')
|
||||
self.assertEqual(ret['saltenv'], 'foo')
|
||||
|
||||
# Ensure that environment overrides saltenv when saltenv not
|
||||
# explicitly passed.
|
||||
defaults = self._get_defaults(environment='foo', saltenv='bar')
|
||||
ret = sconfig.apply_master_config(defaults=defaults)
|
||||
self.assertEqual(ret['environment'], 'bar')
|
||||
self.assertEqual(ret['saltenv'], 'bar')
|
||||
|
||||
# If environment was not explicitly set, it should not be in the
|
||||
# opts at all.
|
||||
defaults = self._get_defaults()
|
||||
ret = sconfig.apply_master_config(defaults=defaults)
|
||||
self.assertNotIn('environment', ret)
|
||||
self.assertEqual(ret['saltenv'], None)
|
||||
|
||||
# Same test as above but with saltenv explicitly set
|
||||
defaults = self._get_defaults(saltenv='foo')
|
||||
ret = sconfig.apply_master_config(defaults=defaults)
|
||||
self.assertNotIn('environment', ret)
|
||||
self.assertEqual(ret['saltenv'], 'foo')
|
||||
|
||||
# MINION CONFIG
|
||||
|
||||
# Ensure that environment overrides saltenv when saltenv not
|
||||
# explicitly passed.
|
||||
defaults = self._get_defaults(environment='foo')
|
||||
ret = sconfig.apply_minion_config(defaults=defaults)
|
||||
self.assertEqual(ret['environment'], 'foo')
|
||||
self.assertEqual(ret['saltenv'], 'foo')
|
||||
|
||||
# Ensure that environment overrides saltenv when saltenv not
|
||||
# explicitly passed.
|
||||
defaults = self._get_defaults(environment='foo', saltenv='bar')
|
||||
ret = sconfig.apply_minion_config(defaults=defaults)
|
||||
self.assertEqual(ret['environment'], 'bar')
|
||||
self.assertEqual(ret['saltenv'], 'bar')
|
||||
|
||||
# If environment was not explicitly set, it should not be in the
|
||||
# opts at all.
|
||||
defaults = self._get_defaults()
|
||||
ret = sconfig.apply_minion_config(defaults=defaults)
|
||||
self.assertNotIn('environment', ret)
|
||||
self.assertEqual(ret['saltenv'], None)
|
||||
|
||||
# Same test as above but with saltenv explicitly set
|
||||
defaults = self._get_defaults(saltenv='foo')
|
||||
ret = sconfig.apply_minion_config(defaults=defaults)
|
||||
self.assertNotIn('environment', ret)
|
||||
self.assertEqual(ret['saltenv'], 'foo')
|
||||
|
Loading…
Reference in New Issue
Block a user