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

[3006.x] Add missing changelog files and a test for salt-ssh CLI fsclient destroy method #64184

Merged
merged 2 commits into from
Apr 28, 2023
Merged
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/64111.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disable class level caching of the file client on `SaltCacheLoader` and properly use context managers to take care of initialization and termination of the file client.
2 changes: 2 additions & 0 deletions changelog/64113.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed several file client uses which were not properly terminating it by switching to using it as a context manager
whenever possible or making sure `.destroy()` was called when using a context manager was not possible.
1 change: 1 addition & 0 deletions changelog/64184.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make sure the `salt-ssh` CLI calls it's `fsclient.destroy()` method when done.
5 changes: 4 additions & 1 deletion salt/cli/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ def run(self):
self.parse_args()

ssh = salt.client.ssh.SSH(self.config)
ssh.run()
try:
ssh.run()
finally:
ssh.fsclient.destroy()
16 changes: 16 additions & 0 deletions tests/pytests/unit/cli/test_ssh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from salt.cli.ssh import SaltSSH
from tests.support.mock import MagicMock, call, patch


def test_fsclient_destroy_called(minion_opts):
"""
Test that `salt.client.ssh.SSH.fsclient.destroy()` is called.
"""
ssh_mock = MagicMock()
with patch(
"salt.utils.parsers.SaltSSHOptionParser.parse_args", return_value=MagicMock()
), patch("salt.client.ssh.SSH", return_value=ssh_mock):
parser = SaltSSH()
parser.config = minion_opts
parser.run()
assert ssh_mock.fsclient.mock_calls == [call.destroy()]