mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 02:00:20 +00:00
Provide execution module a regular file client durring pillar rendering
This commit is contained in:
parent
ecc39aa994
commit
64e0297936
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.
|
|
@ -561,6 +561,7 @@ class Pillar:
|
|||
self.opts = self.__gen_opts(opts, grains, saltenv=saltenv, pillarenv=pillarenv)
|
||||
self.saltenv = saltenv
|
||||
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()
|
||||
|
||||
if opts.get("file_client", "") == "local" and not opts.get(
|
||||
|
@ -573,11 +574,15 @@ class Pillar:
|
|||
utils = salt.loader.utils(opts, file_client=self.client)
|
||||
if opts.get("file_client", "") == "local":
|
||||
self.functions = salt.loader.minion_mods(
|
||||
opts, utils=utils, file_client=self.client
|
||||
opts,
|
||||
utils=utils,
|
||||
file_client=salt.fileclient.ContextlessFileClient(self.fileclient),
|
||||
)
|
||||
else:
|
||||
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:
|
||||
self.functions = functions
|
||||
|
@ -1371,6 +1376,12 @@ class Pillar:
|
|||
except AttributeError:
|
||||
pass
|
||||
|
||||
if self.client:
|
||||
try:
|
||||
self.fileclient.destroy()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# pylint: disable=W1701
|
||||
def __del__(self):
|
||||
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