Do not use __del__ in fileclient

This commit is contained in:
Megan Wilhite 2023-03-24 12:55:55 -06:00
parent af852710e9
commit 834337373c
2 changed files with 29 additions and 6 deletions

View file

@ -1137,12 +1137,6 @@ class RemoteClient(Client):
self.channel = salt.channel.client.ReqChannel.factory(self.opts)
return self.channel
# pylint: disable=no-dunder-del
def __del__(self):
self.destroy()
# pylint: enable=no-dunder-del
def destroy(self):
if self._closing:
return

View file

@ -1278,3 +1278,32 @@ def test_issue_62611(
state_run = next(iter(ret.data.values()))
assert state_run["name"] == "echo MEEP MOOP"
assert state_run["result"] is True
def test_contents_file(salt_master, salt_call_cli, tmp_path):
"""
test calling file.managed multiple times
with salt-call
"""
target_path = tmp_path / "add-contents-file.txt"
sls_name = "file-contents"
sls_contents = """
add_contents_file_sls:
file.managed:
- name: {}
- contents: 1234
""".format(
target_path
)
sls_tempfile = salt_master.state_tree.base.temp_file(
"{}.sls".format(sls_name), sls_contents
)
with sls_tempfile:
for i in range(1, 4):
ret = salt_call_cli.run("state.sls", sls_name)
assert ret.returncode == 0
assert ret.data
state_run = next(iter(ret.data.values()))
assert state_run["result"] is True
# Check to make sure the file was created
assert target_path.is_file()