mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
fix 63724
This commit is contained in:
parent
8da111674a
commit
14a0709271
3 changed files with 23 additions and 1 deletions
1
changelog/63724.fixed.md
Normal file
1
changelog/63724.fixed.md
Normal file
|
@ -0,0 +1 @@
|
|||
have salt.template.compile_template_str cleanup its temp files.
|
|
@ -149,7 +149,9 @@ def compile_template_str(template, renderers, default, blacklist, whitelist):
|
|||
fn_ = salt.utils.files.mkstemp()
|
||||
with salt.utils.files.fopen(fn_, "wb") as ofile:
|
||||
ofile.write(SLS_ENCODER(template)[0])
|
||||
return compile_template(fn_, renderers, default, blacklist, whitelist)
|
||||
ret = compile_template(fn_, renderers, default, blacklist, whitelist)
|
||||
os.unlink(fn_)
|
||||
return ret
|
||||
|
||||
|
||||
def template_shebang(template, renderers, default, blacklist, whitelist, input_data):
|
||||
|
|
19
tests/pytests/unit/test_template.py
Normal file
19
tests/pytests/unit/test_template.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import salt.state
|
||||
from salt import template
|
||||
from salt.config import minion_config
|
||||
from tests.support.mock import MagicMock, patch
|
||||
|
||||
|
||||
def test_compile_template_str_mkstemp_cleanup():
|
||||
with patch("os.unlink", MagicMock()) as unlinked:
|
||||
_config = minion_config(None)
|
||||
_config["file_client"] = "local"
|
||||
_state = salt.state.State(_config)
|
||||
assert template.compile_template_str(
|
||||
"{'val':'test'}",
|
||||
_state.rend,
|
||||
_state.opts["renderer"],
|
||||
_state.opts["renderer_blacklist"],
|
||||
_state.opts["renderer_whitelist"],
|
||||
) == {"val": "test"}
|
||||
unlinked.assert_called_once()
|
Loading…
Add table
Reference in a new issue