mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Provide execution module a regular file client durring pillar rendering
This commit is contained in:
parent
acd688cc04
commit
b0a6a81387
3 changed files with 38 additions and 2 deletions
1
changelog/66124.fixed.md
Normal file
1
changelog/66124.fixed.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Execution modules have access to regular fileclient durring pillar rendering.
|
|
@ -562,6 +562,7 @@ class Pillar:
|
||||||
self.opts = self.__gen_opts(opts, grains, saltenv=saltenv, pillarenv=pillarenv)
|
self.opts = self.__gen_opts(opts, grains, saltenv=saltenv, pillarenv=pillarenv)
|
||||||
self.saltenv = saltenv
|
self.saltenv = saltenv
|
||||||
self.client = salt.fileclient.get_file_client(self.opts, True)
|
self.client = salt.fileclient.get_file_client(self.opts, True)
|
||||||
|
self.fileclient = salt.fileclient.get_file_client(self.opts, False)
|
||||||
self.avail = self.__gather_avail()
|
self.avail = self.__gather_avail()
|
||||||
|
|
||||||
if opts.get("file_client", "") == "local" and not opts.get(
|
if opts.get("file_client", "") == "local" and not opts.get(
|
||||||
|
@ -574,11 +575,15 @@ class Pillar:
|
||||||
utils = salt.loader.utils(opts, file_client=self.client)
|
utils = salt.loader.utils(opts, file_client=self.client)
|
||||||
if opts.get("file_client", "") == "local":
|
if opts.get("file_client", "") == "local":
|
||||||
self.functions = salt.loader.minion_mods(
|
self.functions = salt.loader.minion_mods(
|
||||||
opts, utils=utils, file_client=self.client
|
opts,
|
||||||
|
utils=utils,
|
||||||
|
file_client=salt.fileclient.ContextlessFileClient(self.fileclient),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.functions = salt.loader.minion_mods(
|
self.functions = salt.loader.minion_mods(
|
||||||
self.opts, utils=utils, file_client=self.client
|
self.opts,
|
||||||
|
utils=utils,
|
||||||
|
file_client=salt.fileclient.ContextlessFileClient(self.fileclient),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.functions = functions
|
self.functions = functions
|
||||||
|
@ -1370,6 +1375,12 @@ class Pillar:
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
if self.client:
|
||||||
|
try:
|
||||||
|
self.fileclient.destroy()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
|
||||||
# pylint: disable=W1701
|
# pylint: disable=W1701
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
24
tests/pytests/integration/pillar/test_fileclient.py
Normal file
24
tests/pytests/integration/pillar/test_fileclient.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
def test_pillar_using_cp_module(salt_master, salt_minion, salt_cli, tmp_path):
|
||||||
|
pillar_top = """
|
||||||
|
base:
|
||||||
|
"*":
|
||||||
|
- my_pillar
|
||||||
|
"""
|
||||||
|
my_pillar = """
|
||||||
|
{{% set file_content = salt.cp.get_file_str("{}") %}}
|
||||||
|
""".format(
|
||||||
|
str(tmp_path / "myfile.txt")
|
||||||
|
)
|
||||||
|
my_file = """
|
||||||
|
foobar
|
||||||
|
"""
|
||||||
|
(tmp_path / "myfile.txt").write_text(my_file)
|
||||||
|
with salt_master.pillar_tree.base.temp_file("top.sls", pillar_top):
|
||||||
|
with salt_master.pillar_tree.base.temp_file("my_pillar.sls", my_pillar):
|
||||||
|
with salt_master.pillar_tree.base.temp_file("my_pillar.sls", my_pillar):
|
||||||
|
ret = salt_cli.run("state.apply", minion_tgt=salt_minion.id)
|
||||||
|
assert ret.returncode == 1
|
||||||
|
assert (
|
||||||
|
ret.json["no_|-states_|-states_|-None"]["comment"]
|
||||||
|
== "No states found for this minion"
|
||||||
|
)
|
Loading…
Add table
Reference in a new issue