fix 63724

This commit is contained in:
Thomas Phipps 2023-03-22 23:37:59 +00:00 committed by Pedro Algarvio
parent 8da111674a
commit 14a0709271
3 changed files with 23 additions and 1 deletions

1
changelog/63724.fixed.md Normal file
View file

@ -0,0 +1 @@
have salt.template.compile_template_str cleanup its temp files.

View file

@ -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):

View 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()