mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Fixed file client private attribute reference on SaltMakoTemplateLookup
Fixes #64280 Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
3ae4e2aba5
commit
560ab52ccf
3 changed files with 33 additions and 2 deletions
1
changelog/64280.fixed.md
Normal file
1
changelog/64280.fixed.md
Normal file
|
@ -0,0 +1 @@
|
|||
Fixed file client private attribute reference on `SaltMakoTemplateLookup`
|
|
@ -99,8 +99,10 @@ if HAS_MAKO:
|
|||
)
|
||||
|
||||
def destroy(self):
|
||||
if self.client:
|
||||
if self._file_client:
|
||||
file_client = self._file_client
|
||||
self._file_client = None
|
||||
try:
|
||||
self.client.destroy()
|
||||
file_client.destroy()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
|
28
tests/pytests/unit/utils/test_mako.py
Normal file
28
tests/pytests/unit/utils/test_mako.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
import pytest
|
||||
|
||||
from tests.support.mock import Mock, call, patch
|
||||
|
||||
pytest.importorskip("mako")
|
||||
|
||||
# This import needs to be after the above importorskip so that no ImportError
|
||||
# is raised if Mako is not installed
|
||||
from salt.utils.mako import SaltMakoTemplateLookup
|
||||
|
||||
|
||||
def test_mako_template_lookup(minion_opts):
|
||||
"""
|
||||
The shudown method can be called without raising an exception when the
|
||||
file_client does not have a destroy method
|
||||
"""
|
||||
# Test SaltCacheLoader creating and destroying the file client created
|
||||
file_client = Mock()
|
||||
with patch("salt.fileclient.get_file_client", return_value=file_client):
|
||||
loader = SaltMakoTemplateLookup(minion_opts)
|
||||
assert loader._file_client is None
|
||||
assert loader.file_client() is file_client
|
||||
assert loader._file_client is file_client
|
||||
try:
|
||||
loader.destroy()
|
||||
except AttributeError:
|
||||
pytest.fail("Regression when calling SaltMakoTemplateLookup.destroy()")
|
||||
assert file_client.mock_calls == [call.destroy()]
|
Loading…
Add table
Reference in a new issue