mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
init changes from dmitry PR
This commit is contained in:
parent
0796d7c88b
commit
954ccb4390
4 changed files with 60 additions and 7 deletions
|
@ -2213,8 +2213,19 @@ def minion_config(
|
|||
overrides, defaults, cache_minion_id=cache_minion_id, minion_id=minion_id
|
||||
)
|
||||
opts["__role"] = role
|
||||
if role != "master":
|
||||
apply_sdb(opts)
|
||||
_validate_opts(opts)
|
||||
return opts
|
||||
|
||||
|
||||
def mminion_config(path, overrides, ignore_config_errors=True):
|
||||
opts = minion_config(path, ignore_config_errors=ignore_config_errors, role="master")
|
||||
opts.update(overrides)
|
||||
apply_sdb(opts)
|
||||
_validate_opts(opts)
|
||||
opts["grains"] = salt.loader.grains(opts)
|
||||
opts["pillar"] = {}
|
||||
return opts
|
||||
|
||||
|
||||
|
|
|
@ -969,13 +969,10 @@ class MasterMinion:
|
|||
whitelist=None,
|
||||
ignore_config_errors=True,
|
||||
):
|
||||
self.opts = salt.config.minion_config(
|
||||
opts["conf_file"], ignore_config_errors=ignore_config_errors, role="master"
|
||||
self.opts = salt.config.mminion_config(
|
||||
opts["conf_file"], opts, ignore_config_errors=ignore_config_errors
|
||||
)
|
||||
self.opts.update(opts)
|
||||
self.whitelist = whitelist
|
||||
self.opts["grains"] = salt.loader.grains(opts)
|
||||
self.opts["pillar"] = {}
|
||||
self.mk_returners = returners
|
||||
self.mk_states = states
|
||||
self.mk_rend = rend
|
||||
|
|
|
@ -265,9 +265,9 @@ class ConfigTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
|
|||
|
||||
@with_tempfile()
|
||||
def test_proper_path_joining(self, fpath):
|
||||
temp_config = "root_dir: /\n" "key_logfile: key\n"
|
||||
temp_config = "root_dir: /\nkey_logfile: key\n"
|
||||
if salt.utils.platform.is_windows():
|
||||
temp_config = "root_dir: c:\\\n" "key_logfile: key\n"
|
||||
temp_config = "root_dir: c:\\\nkey_logfile: key\n"
|
||||
with salt.utils.files.fopen(fpath, "w") as fp_:
|
||||
fp_.write(temp_config)
|
||||
|
||||
|
@ -1886,6 +1886,42 @@ class ConfigTestCase(TestCase, AdaptedConfigurationTestCaseMixin):
|
|||
self.assertNotIn("environment", ret)
|
||||
self.assertEqual(ret["saltenv"], "foo")
|
||||
|
||||
@with_tempfile()
|
||||
def test_minion_config_role_master(self, fpath):
|
||||
with salt.utils.files.fopen(fpath, "w") as wfh:
|
||||
wfh.write("root_dir: /\n" "key_logfile: key\n")
|
||||
with patch("salt.config.apply_sdb") as apply_sdb_mock, patch(
|
||||
"salt.config._validate_opts"
|
||||
) as validate_opts_mock:
|
||||
config = salt.config.minion_config(fpath, role="master")
|
||||
apply_sdb_mock.assert_not_called()
|
||||
validate_opts_mock.assert_not_called()
|
||||
self.assertEqual(config["__role"], "master")
|
||||
|
||||
@with_tempfile()
|
||||
def test_mminion_config_cache_path(self, fpath):
|
||||
cachedir = os.path.abspath("/path/to/master/cache")
|
||||
overrides = {}
|
||||
|
||||
with salt.utils.files.fopen(fpath, "w") as wfh:
|
||||
wfh.write(
|
||||
"root_dir: /\n" "key_logfile: key\n" "cachedir: {}".format(cachedir)
|
||||
)
|
||||
config = salt.config.mminion_config(fpath, overrides)
|
||||
self.assertEqual(config["__role"], "master")
|
||||
self.assertEqual(config["cachedir"], cachedir)
|
||||
|
||||
@with_tempfile()
|
||||
def test_mminion_config_cache_path_overrides(self, fpath):
|
||||
cachedir = os.path.abspath("/path/to/master/cache")
|
||||
overrides = {"cachedir": cachedir}
|
||||
|
||||
with salt.utils.files.fopen(fpath, "w") as wfh:
|
||||
wfh.write("root_dir: /\n" "key_logfile: key\n")
|
||||
config = salt.config.mminion_config(fpath, overrides)
|
||||
self.assertEqual(config["__role"], "master")
|
||||
self.assertEqual(config["cachedir"], cachedir)
|
||||
|
||||
|
||||
class APIConfigTestCase(DefaultConfigsBase, TestCase):
|
||||
"""
|
||||
|
|
|
@ -794,3 +794,12 @@ class MinionAsyncTestCase(
|
|||
with self.assertRaises(SaltClientError, msg="No master could be resolved"):
|
||||
minion = salt.minion.Minion(mock_opts)
|
||||
yield minion.connect_master()
|
||||
|
||||
|
||||
class MasterMinionTestCase(TestCase):
|
||||
def test_config_cache_path_overrides(self):
|
||||
cachedir = os.path.abspath("/path/to/master/cache")
|
||||
opts = {"cachedir": cachedir, "conf_file": None}
|
||||
|
||||
mminion = salt.minion.MasterMinion(opts)
|
||||
self.assertEqual(mminion.opts["cachedir"], cachedir)
|
||||
|
|
Loading…
Add table
Reference in a new issue