Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair SaltMakoTemplateLookup AttributeError #694

Open
wants to merge 1 commit into
base: openSUSE/release/3006.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/64280.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed file client private attribute reference on `SaltMakoTemplateLookup`
6 changes: 4 additions & 2 deletions salt/utils/mako.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ def cache_file(self, fpath):
)

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 changes: 28 additions & 0 deletions tests/pytests/unit/utils/test_mako.py
Original file line number Diff line number Diff line change
@@ -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